/** * Get page's metadatas. * * @param Page $page the page we want to get its metadatas * * @return \Symfony\Component\HttpFoundation\Response * * @Rest\ParamConverter(name="page", class="BackBee\NestedNode\Page") */ public function getMetadataAction(Page $page) { $metadata = null !== $page->getMetaData() ? $page->getMetaData()->jsonSerialize() : array(); if (empty($metadata)) { $metadata = $this->application->getContainer()->get('nestednode.metadata.resolver')->resolve($page); } return $this->createJsonResponse($metadata); }
/** * @covers BackBee\NestedNode\Page::setMetaData */ public function testSetMetaData() { $meta = new MetaDataBag(); $this->assertEquals($this->page, $this->page->setMetaData($meta)); $this->assertEquals($meta, $this->page->getMetaData()); $this->assertEquals($this->page, $this->page->setMetaData(null)); $this->assertNull($this->page->getMetaData()); }
/** * Update page's metadatas. * * @param Page $page the page we want to update its metadatas * @param Request $request * * @return Symfony\Component\HttpFoundation\Response * * @Rest\ParamConverter(name="page", class="BackBee\NestedNode\Page") */ public function putMetadataAction(Page $page, Request $request) { $metadatas = $page->getMetaData(); foreach ($request->request->all() as $name => $attributes) { if ($metadatas->has($name)) { foreach ($attributes as $attr_name => $attr_value) { if ($attr_value !== $metadatas->get($name)->getAttribute($attr_name)) { $metadatas->get($name)->setAttribute($attr_name, $attr_value); } } } } $page->setMetaData($metadatas->compute($page)); $this->getApplication()->getEntityManager()->flush($page); return $this->createJsonResponse(null, 204); }
/** * Returns computed metadata from provided $page. * * @param Page|NULL $page * * @return MetaDataBag */ public function resolve(Page $page = null) { if (null === $page || null === ($metadataBag = $page->getMetaData())) { $metadataBag = new MetaDataBag(); } if (!is_array($this->definitions)) { return $metadataBag; } foreach ($this->definitions as $name => $definition) { if (!is_array($definition)) { continue; } if (null === ($metadata = $metadataBag->get($name))) { $metadata = new MetaData($name); $metadataBag->add($metadata); } $this->parseDefinition($definition, $metadata, $page); } return clone $metadataBag; }