vendor/sonata-project/admin-bundle/src/Block/AdminListBlockService.php line 46

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\AdminBundle\Block;
  12. use Sonata\AdminBundle\Admin\Pool;
  13. use Sonata\AdminBundle\Templating\TemplateRegistryInterface;
  14. use Sonata\BlockBundle\Block\BlockContextInterface;
  15. use Sonata\BlockBundle\Block\Service\AbstractBlockService;
  16. use Symfony\Component\HttpFoundation\Response;
  17. use Symfony\Component\OptionsResolver\OptionsResolver;
  18. use Twig\Environment;
  19. /**
  20.  * @author Thomas Rabaix <thomas.rabaix@sonata-project.org>
  21.  */
  22. final class AdminListBlockService extends AbstractBlockService
  23. {
  24.     private Pool $pool;
  25.     private TemplateRegistryInterface $templateRegistry;
  26.     public function __construct(
  27.         Environment $twig,
  28.         Pool $pool,
  29.         TemplateRegistryInterface $templateRegistry
  30.     ) {
  31.         parent::__construct($twig);
  32.         $this->pool $pool;
  33.         $this->templateRegistry $templateRegistry;
  34.     }
  35.     public function execute(BlockContextInterface $blockContext, ?Response $response null): Response
  36.     {
  37.         $dashboardGroups $this->pool->getDashboardGroups();
  38.         $settings $blockContext->getSettings();
  39.         $visibleGroups = [];
  40.         foreach ($dashboardGroups as $name => $dashboardGroup) {
  41.             if (false === $settings['groups'] || \in_array($name$settings['groups'], true)) {
  42.                 $visibleGroups[] = $dashboardGroup;
  43.             }
  44.         }
  45.         return $this->renderResponse($this->templateRegistry->getTemplate('list_block'), [
  46.             'block' => $blockContext->getBlock(),
  47.             'settings' => $settings,
  48.             'groups' => $visibleGroups,
  49.         ], $response);
  50.     }
  51.     public function configureSettings(OptionsResolver $resolver): void
  52.     {
  53.         $resolver->setDefaults([
  54.             'groups' => false,
  55.         ]);
  56.         $resolver->setAllowedTypes('groups', ['bool''array']);
  57.     }
  58. }