diff --git a/src/Controller/BlockAdminController.php b/src/Controller/BlockAdminController.php index 795808e78..ef6679b8f 100644 --- a/src/Controller/BlockAdminController.php +++ b/src/Controller/BlockAdminController.php @@ -16,6 +16,7 @@ use Sonata\AdminBundle\Controller\CRUDController; use Sonata\AdminBundle\Exception\BadRequestParamHttpException; use Sonata\BlockBundle\Block\BlockServiceManagerInterface; +use Sonata\BlockBundle\Block\Service\EditableBlockService; use Sonata\PageBundle\Model\BlockInteractorInterface; use Sonata\PageBundle\Model\PageBlockInterface; use Symfony\Component\HttpFoundation\Request; @@ -87,12 +88,22 @@ public function createAction(Request $request): Response $parameters = $this->admin->getPersistentParameters(); - $blockManager = $this->container->get('sonata.block.manager'); - \assert($blockManager instanceof BlockServiceManagerInterface); - if (null === $parameters['type']) { + $blockManager = $this->container->get('sonata.block.manager'); + \assert($blockManager instanceof BlockServiceManagerInterface); + + $blockServices = $blockManager->getServicesByContext('sonata_page_bundle'); + + foreach ($blockServices as $code => $service) { + if ($service instanceof EditableBlockService) { + continue; + } + + unset($blockServices[$code]); + } + return $this->renderWithExtraParams('@SonataPage/BlockAdmin/select_type.html.twig', [ - 'services' => $blockManager->getServicesByContext('sonata_page_bundle'), + 'blockServices' => $blockServices, 'base_template' => $this->getBaseTemplate(), 'admin' => $this->admin, 'action' => 'create', @@ -159,12 +170,12 @@ public function composePreviewAction(Request $request): Response $blockManager = $this->container->get('sonata.block.manager'); \assert($blockManager instanceof BlockServiceManagerInterface); - $blockServices = $blockManager->getServicesByContext('sonata_page_bundle', false); + $blockService = $blockManager->get($existingObject); return $this->renderWithExtraParams('@SonataPage/BlockAdmin/compose_preview.html.twig', [ 'container' => $container, 'child' => $existingObject, - 'blockServices' => $blockServices, + 'blockService' => $blockService, 'blockAdmin' => $this->admin, ]); } diff --git a/src/Controller/PageAdminController.php b/src/Controller/PageAdminController.php index 1e23fe065..591995720 100644 --- a/src/Controller/PageAdminController.php +++ b/src/Controller/PageAdminController.php @@ -16,6 +16,7 @@ use Sonata\AdminBundle\Controller\CRUDController; use Sonata\AdminBundle\Datagrid\ProxyQueryInterface; use Sonata\BlockBundle\Block\BlockServiceManagerInterface; +use Sonata\BlockBundle\Block\Service\EditableBlockService; use Sonata\PageBundle\Admin\BlockAdmin; use Sonata\PageBundle\Admin\SnapshotAdmin; use Sonata\PageBundle\Model\BlockInteractorInterface; @@ -273,6 +274,14 @@ public function composeContainerShowAction(Request $request): Response \assert($blockManager instanceof BlockServiceManagerInterface); $blockServices = $blockManager->getServicesByContext('sonata_page_bundle', false); + foreach ($blockServices as $code => $blockService) { + if ($blockService instanceof EditableBlockService) { + continue; + } + + unset($blockServices[$code]); + } + $page = $block->getPage(); $blockCode = $block->getSetting('code'); @@ -295,7 +304,7 @@ public function composeContainerShowAction(Request $request): Response $container = $template->getContainer($blockCode); if (null !== $container && \count($container['blocks']) > 0) { - foreach ($blockServices as $code => $service) { + foreach ($blockServices as $code => $blockService) { if (\in_array($code, $container['blocks'], true)) { continue; } diff --git a/src/Resources/views/BlockAdmin/compose_preview.html.twig b/src/Resources/views/BlockAdmin/compose_preview.html.twig index c5310a4ec..f04655e39 100644 --- a/src/Resources/views/BlockAdmin/compose_preview.html.twig +++ b/src/Resources/views/BlockAdmin/compose_preview.html.twig @@ -4,9 +4,7 @@ data-block-enabled="{{ child.enabled|default('0') }}" data-block-type="{{ child.type }}" > - {% set service = attribute(blockServices, child.type) ?? null %} - - {% if service %} + {% if blockService %} {% endif %} - {% if service %} - {% set metadataTitle = service.metadata.title|trans({}, service.metadata.domain|default('SonataPageBundle')) %} + {% if blockService %} + {% set metadataTitle = blockService.metadata.title|trans({}, blockService.metadata.domain|default('SonataPageBundle')) %} {% set blockTitle = child.name|default(metadataTitle) %} - {% set blockImage = service.metadata.image ? asset(service.metadata.image) : null %} - {% set blockClass = service.metadata.option('class') %} + {% set blockImage = blockService.metadata.image ? asset(blockService.metadata.image) : null %} + {% set blockClass = blockService.metadata.option('class') %} {% else %} {% set metadataTitle = child.type %} {% set blockTitle = child.name %} @@ -36,13 +34,13 @@ {{ metadataTitle }} - {% if service %} + {% if blockService %} {% endif %} - {% if service %} + {% if blockService %} {% else %} diff --git a/src/Resources/views/BlockAdmin/select_type.html.twig b/src/Resources/views/BlockAdmin/select_type.html.twig index 25218f96c..1f0a444cb 100644 --- a/src/Resources/views/BlockAdmin/select_type.html.twig +++ b/src/Resources/views/BlockAdmin/select_type.html.twig @@ -21,28 +21,23 @@ file that was distributed with this source code.