vendor/sonata-project/block-bundle/src/Block/Service/TemplateBlockService.php line 31

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4.  * This file is part of the Sonata Project package.
  5.  *
  6.  * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
  7.  *
  8.  * For the full copyright and license information, please view the LICENSE
  9.  * file that was distributed with this source code.
  10.  */
  11. namespace Sonata\BlockBundle\Block\Service;
  12. use Sonata\AdminBundle\Form\FormMapper;
  13. use Sonata\BlockBundle\Block\BlockContextInterface;
  14. use Sonata\BlockBundle\Meta\Metadata;
  15. use Sonata\BlockBundle\Model\BlockInterface;
  16. use Sonata\Form\Type\ImmutableArrayType;
  17. use Symfony\Component\HttpFoundation\Response;
  18. use Symfony\Component\OptionsResolver\OptionsResolver;
  19. /**
  20.  * @final since sonata-project/block-bundle 3.0
  21.  *
  22.  * @author Thomas Rabaix <thomas.rabaix@sonata-project.org>
  23.  */
  24. class TemplateBlockService extends AbstractAdminBlockService
  25. {
  26.     public function execute(BlockContextInterface $blockContextResponse $response null)
  27.     {
  28.         return $this->renderResponse($blockContext->getTemplate(), [
  29.             'block' => $blockContext->getBlock(),
  30.             'settings' => $blockContext->getSettings(),
  31.         ], $response);
  32.     }
  33.     public function buildEditForm(FormMapper $formMapperBlockInterface $block)
  34.     {
  35.         $formMapper->add('settings'ImmutableArrayType::class, [
  36.             'keys' => [
  37.                 ['template'null, [
  38.                     'label' => 'form.label_template',
  39.                 ]],
  40.             ],
  41.             'translation_domain' => 'SonataBlockBundle',
  42.         ]);
  43.     }
  44.     public function configureSettings(OptionsResolver $resolver)
  45.     {
  46.         $resolver->setDefaults([
  47.             'template' => '@SonataBlock/Block/block_template.html.twig',
  48.         ]);
  49.     }
  50.     public function getBlockMetadata($code null)
  51.     {
  52.         return new Metadata($this->getName(), (null !== $code $code $this->getName()), false'SonataBlockBundle', [
  53.             'class' => 'fa fa-code',
  54.         ]);
  55.     }
  56. }