Exemple #1
0
 /**
  * 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();
     $default_metadata = new MetaDataBag($this->getApplication()->getConfig()->getSection('metadata'));
     $metadata = array_merge($default_metadata->jsonSerialize(), $metadata);
     return $this->createJsonResponse($metadata);
 }
 /**
  * Get page's metadatas.
  *
  * @param Page $page the page we want to get its metadatas
  *
  * @return \Symfony\Component\HttpFoundation\Response
  *
  */
 public function getMetadataAction(Request $request, $uid)
 {
     //     * @ParamConverter(name="page", class="BackBee\CoreDomain\NestedNode\Page")
     $page = $this->getEntity('BackBee\\CoreDomain\\NestedNode\\Page', $uid);
     $metadata = null !== $page->getMetaData() ? $page->getMetaData()->jsonSerialize() : array();
     $default_metadata = new MetaDataBag($this->getParameter('bbapp.metadata_config'));
     $metadata = array_merge($default_metadata->jsonSerialize(), $metadata);
     return $this->createJsonResponse($metadata);
 }
Exemple #3
0
 /**
  * @covers BackBee\MetaData\MetaDataBag::jsonSerialize
  */
 public function testJsonSerialize()
 {
     $meta1 = new MetaData('test1');
     $meta1->setAttribute('name', 'test1');
     $meta1->setAttribute('content', 'content of test1');
     $meta1->setAttribute('lang', 'fr');
     $meta2 = new MetaData('test2');
     $meta2->setAttribute('name', 'test2');
     $meta2->setAttribute('content', 'content of test2');
     $meta2->setAttribute('lang', 'en');
     $bag = new MetaDataBag();
     $bag->add($meta1)->add($meta2);
     $expected = ['test1' => ['content' => 'content of test1', 'lang' => 'fr'], 'test2' => ['content' => 'content of test2', 'lang' => 'en']];
     $this->assertEquals($expected, $bag->jsonSerialize());
 }
Exemple #4
0
 /**
  * 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;
 }