/**
  * {@inheritdoc}
  */
 public function execute(BlockInterface $block, Response $response = null)
 {
     $parameters = (array) json_decode($block->getSetting('parameters'), true);
     $parameters = array_merge($parameters, array('_block' => $block));
     $settings = array_merge($this->getDefaultSettings(), (array) $block->getSettings());
     try {
         $actionContent = $this->kernel->render($settings['action'], $parameters);
     } catch (\Exception $e) {
         throw $e;
     }
     $content = self::mustache($block->getSetting('layout'), array('CONTENT' => $actionContent));
     return $this->renderResponse('SonataBlockBundle:Block:block_core_action.html.twig', array('content' => $content, 'block' => $block), $response);
 }
 /**
  * {@inheritdoc}
  */
 public function validateBlock(ErrorElement $errorElement, BlockInterface $block)
 {
     if (($name = $block->getSetting('menu_name')) && $name !== '' && !$this->menuProvider->has($name)) {
         // If we specified a menu_name, check that it exists
         $errorElement->with('menu_name')->addViolation('sonata.block.menu.not_existing', array('name' => $name))->end();
     }
 }
 /**
  * {@inheritdoc}
  */
 public function buildEditForm(FormMapper $formMapper, BlockInterface $block)
 {
     $contextChoices = $this->getContextChoices();
     $formatChoices = $this->getFormatChoices($block->getSetting('mediaId'));
     $translator = $this->container->get('translator');
     $formMapper->add('settings', 'sonata_type_immutable_array', array('keys' => array(array('title', 'text', array('required' => false)), array('content', 'textarea', array('required' => false)), array('orientation', 'choice', array('choices' => array('left' => $translator->trans('feature_left_choice', array(), 'SonataMediaBundle'), 'right' => $translator->trans('feature_right_choice', array(), 'SonataMediaBundle')))), array('context', 'choice', array('required' => true, 'choices' => $contextChoices)), array('format', 'choice', array('required' => count($formatChoices) > 0, 'choices' => $formatChoices)), array($this->getMediaBuilder($formMapper), null, array()))));
 }
示例#4
0
 /**
  * {@inheritdoc}
  */
 public function buildEditForm(FormMapper $formMapper, BlockInterface $block)
 {
     if (!$block->getSetting('mediaId') instanceof MediaInterface) {
         $this->load($block);
     }
     $formatChoices = $this->getFormatChoices($block->getSetting('mediaId'));
     $keys[] = array('title', 'text', array('required' => false));
     $keys[] = array($this->getMediaBuilder($formMapper), null, array());
     $keys[] = array('format', 'choice', array('required' => count($formatChoices) > 0, 'choices' => $formatChoices));
     if ($this->getTemplates()) {
         $keys[] = array('template', 'choice', array('choices' => $this->getTemplates()));
     }
     $formMapper->add('settings', 'sonata_type_immutable_array', array('keys' => $keys, 'attr' => array('class' => 'bruery-immutable-container')));
 }
 /**
  * {@inheritdoc}
  */
 public function preUpdate(BlockInterface $block)
 {
     $block->setSetting('galleryId', is_object($block->getSetting('galleryId')) ? $block->getSetting('galleryId')->getId() : null);
 }
 /**
  * {@inheritdoc}
  */
 public function load(BlockInterface $block)
 {
     if (is_numeric($block->getSetting('pageId', null))) {
         $cmsManager = $this->cmsManagerSelector->retrieve();
         $site = $block->getPage()->getSite();
         $block->setSetting('pageId', $cmsManager->getPage($site, $block->getSetting('pageId')));
     }
 }
 /**
  * @param BlockInterface $block
  */
 private function resolveIds(BlockInterface $block)
 {
     $block->setSetting('collectionId', is_object($block->getSetting('collectionId')) ? $block->getSetting('collectionId')->getId() : null);
 }
 /**
  * {@inheritdoc}
  */
 public function buildEditForm(FormMapper $formMapper, BlockInterface $block)
 {
     $formatChoices = $this->getFormatChoices($block->getSetting('mediaId'));
     $formMapper->add('settings', 'sonata_type_immutable_array', array('keys' => array(array('title', 'text', array('required' => false, 'label' => 'form.label_title')), array('content', 'textarea', array('required' => false, 'label' => 'form.label_content')), array('orientation', 'choice', array('required' => false, 'choices' => array('left' => 'form.label_orientation_left', 'right' => 'form.label_orientation_right'), 'label' => 'form.label_orientation')), array($this->getMediaBuilder($formMapper), null, array()), array('format', 'choice', array('required' => count($formatChoices) > 0, 'choices' => $formatChoices, 'label' => 'form.label_format'))), 'translation_domain' => 'SonataMediaBundle'));
 }
 /**
  * {@inheritdoc}
  */
 public function load(BlockInterface $block)
 {
     foreach ($block->getTranslations() as $trans) {
         $sharedBlock = $trans->getSetting('blockId', null);
         if (is_int($sharedBlock)) {
             $sharedBlock = $this->blockManager->findOneBy(array('id' => $sharedBlock));
         }
         $trans->setSetting('blockId', $sharedBlock);
     }
     $sharedBlock = $block->getSetting('blockId', null);
     if (is_int($sharedBlock)) {
         $sharedBlock = $this->blockManager->findOneBy(array('id' => $sharedBlock));
     }
     $block->setSetting('blockId', $sharedBlock);
 }