Exemplo n.º 1
0
 /**
  * Add translations
  *
  * @param \Symbio\OrangeGate\PageBundle\Entity\PageTranslation $translations
  * @return Block
  */
 public function addTranslation(BlockTranslation $translations)
 {
     $this->translations[$translations->getLocale()] = $translations;
     return $this;
 }
 /**
  * {@inheritdoc}
  */
 public function createNewContainer(array $values = array(), \Closure $alter = null)
 {
     $container = $this->blockManager->create();
     $container->setEnabled(isset($values['enabled']) ? $values['enabled'] : true);
     $container->setCreatedAt(new \DateTime());
     $container->setUpdatedAt(new \DateTime());
     $container->setType('sonata.page.block.container');
     if (isset($values['page'])) {
         $container->setPage($values['page']);
     }
     if (isset($values['name'])) {
         $container->setName($values['name']);
     } else {
         $container->setName(isset($values['code']) ? $values['code'] : 'No name defined');
     }
     $container->setSettings(array('code' => isset($values['code']) ? $values['code'] : 'no code defined'));
     $container->setPosition(isset($values['position']) ? $values['position'] : 1);
     if (isset($values['parent'])) {
         $container->setParent($values['parent']);
     }
     if ($page = $container->getPage()) {
         foreach ($page->getTranslations() as $locale => $trans) {
             $bt = new BlockTranslation();
             $bt->setLocale($locale);
             $bt->setObject($container);
             $bt->setEnabled(isset($values['enabled']) ? $values['enabled'] : true);
             $bt->setSettings($container->getSettings());
             $container->addTranslation($bt);
         }
     }
     if ($alter) {
         $alter($container);
     }
     $this->blockManager->save($container);
     return $container;
 }
 protected function deepCopyBlockTranslation(BlockTranslation $translation, Block $parent)
 {
     $copy = new BlockTranslation();
     $copy->setLocale($translation->getLocale());
     $copy->setObject($parent);
     $copy->setEnabled($translation->getEnabled());
     $copy->setSettings($translation->getSettings());
     return $copy;
 }
 /**
  * @param array         $content
  * @param PageInterface $page
  *
  * @return BlockInterface
  */
 public function loadBlock(array $content, PageInterface $page)
 {
     $block = $this->blockManager->create();
     $content = $this->fixBlockContent($content);
     $block->setPage($page);
     $block->setId($content['id']);
     $block->setName($content['name']);
     $block->setEnabled($content['enabled']);
     $block->setPosition($content['position']);
     $block->setSettings($content['settings']);
     $block->setType($content['type']);
     $createdAt = new \DateTime();
     $createdAt->setTimestamp($content['created_at']);
     $block->setCreatedAt($createdAt);
     $updatedAt = new \DateTime();
     $updatedAt->setTimestamp($content['updated_at']);
     $block->setUpdatedAt($updatedAt);
     $t = new BlockTranslation();
     $t->setObject($block);
     $t->setLocale($page->getSite()->getLocale());
     $t->setEnabled($content['enabled']);
     $t->setSettings($content['settings']);
     $block->addTranslation($t);
     foreach ($content['blocks'] as $child) {
         $block->addChildren($this->loadBlock($child, $page));
     }
     return $block;
 }