src/Nolimit/Country/Admin/CountryAdmin.php line 15

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Nolimit\Country\Admin;
  4. use App\Entity\Country;
  5. use App\Entity\Traits\ToStringNameTrait;
  6. use Sonata\AdminBundle\Admin\AbstractAdmin;
  7. use Sonata\AdminBundle\Datagrid\DatagridMapper;
  8. use Sonata\AdminBundle\Datagrid\ListMapper;
  9. use Sonata\AdminBundle\Form\FormMapper;
  10. use Sonata\AdminBundle\Show\ShowMapper;
  11. final class CountryAdmin extends AbstractAdmin
  12. {
  13.     use ToStringNameTrait;
  14.     protected function configureDatagridFilters(DatagridMapper $filter): void
  15.     {
  16.         $filter
  17.             ->add('name')
  18.             ;
  19.     }
  20.     protected function configureListFields(ListMapper $list): void
  21.     {
  22.         $list
  23.             ->add('name')
  24.             ->add('isDefault')
  25.             ->add(ListMapper::NAME_ACTIONSnull, [
  26.                 'actions' => [
  27.                     'show' => [],
  28.                     'edit' => [],
  29.                     'delete' => [],
  30.                 ],
  31.             ]);
  32.     }
  33.     protected function configureFormFields(FormMapper $form): void
  34.     {
  35.         $form
  36.             ->add('name')
  37.             ->add('isDefault')
  38.             ;
  39.     }
  40.     protected function configureShowFields(ShowMapper $show): void
  41.     {
  42.         $show
  43.             ->add('name')
  44.             ->add('isDefault')
  45.             ;
  46.     }
  47.     public function toString($object): string
  48.     {
  49.         return $object instanceof Country
  50.             $object->getName()
  51.             : 'Entity name is missing'// shown in the breadcrumb on the create view
  52.     }
  53. }