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

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.     public function __construct(
  25.         Environment $twig,
  26.         private Pool $pool,
  27.         private TemplateRegistryInterface $templateRegistry
  28.     ) {
  29.         parent::__construct($twig);
  30.     }
  31.     public function execute(BlockContextInterface $blockContext, ?Response $response null): Response
  32.     {
  33.         $dashboardGroups $this->pool->getDashboardGroups();
  34.         $settings $blockContext->getSettings();
  35.         $visibleGroups = [];
  36.         foreach ($dashboardGroups as $name => $dashboardGroup) {
  37.             if (false === $settings['groups'] || \in_array($name$settings['groups'], true)) {
  38.                 $visibleGroups[] = $dashboardGroup;
  39.             }
  40.         }
  41.         return $this->renderResponse($this->templateRegistry->getTemplate('list_block'), [
  42.             'block' => $blockContext->getBlock(),
  43.             'settings' => $settings,
  44.             'groups' => $visibleGroups,
  45.         ], $response);
  46.     }
  47.     public function configureSettings(OptionsResolver $resolver): void
  48.     {
  49.         $resolver->setDefaults([
  50.             'groups' => false,
  51.         ]);
  52.         $resolver->setAllowedTypes('groups', ['bool''array']);
  53.     }
  54. }