vendor/sonata-project/media-bundle/src/Admin/ORM/MediaAdmin.php line 28

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\MediaBundle\Admin\ORM;
  12. use Sonata\AdminBundle\Datagrid\DatagridMapper;
  13. use Sonata\DoctrineORMAdminBundle\Filter\ChoiceFilter;
  14. use Sonata\MediaBundle\Admin\BaseMediaAdmin as Admin;
  15. use Sonata\MediaBundle\Model\MediaInterface;
  16. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  17. /**
  18.  * @final since sonata-project/media-bundle 3.21.0
  19.  *
  20.  * @phpstan-template T of MediaInterface
  21.  * @phpstan-extends Admin<T>
  22.  */
  23. class MediaAdmin extends Admin
  24. {
  25.     protected function configureDatagridFilters(DatagridMapper $filter)
  26.     {
  27.         $options = [
  28.             'choices' => [],
  29.         ];
  30.         foreach ($this->pool->getContexts() as $name => $context) {
  31.             $options['choices'][$name] = $name;
  32.         }
  33.         $filter
  34.             ->add('name')
  35.             ->add('providerReference')
  36.             ->add('enabled')
  37.             ->add('context'null, [
  38.                 'show_filter' => true !== $this->getPersistentParameter('hide_context'),
  39.             ], ChoiceType::class, $options);
  40.         if (null !== $this->categoryManager) {
  41.             $filter->add('category'null, ['show_filter' => false]);
  42.         }
  43.         $filter
  44.             ->add('width')
  45.             ->add('height')
  46.             ->add('contentType');
  47.         $providers = [];
  48.         $providerNames = (array) $this->pool->getProviderNamesByContext($this->getPersistentParameter('context') ?? $this->pool->getDefaultContext());
  49.         foreach ($providerNames as $name) {
  50.             $providers[$name] = $name;
  51.         }
  52.         $filter->add('providerName'ChoiceFilter::class, [
  53.             'field_options' => [
  54.                 'choices' => $providers,
  55.                 'required' => false,
  56.                 'multiple' => false,
  57.                 'expanded' => false,
  58.             ],
  59.             'field_type' => ChoiceType::class,
  60.         ]);
  61.     }
  62. }