src/Admin/ProductAdmin.php line 29

Open in your IDE?
  1. <?php
  2. namespace App\Admin;
  3. use App\Entity\Seo;
  4. use Doctrine\ORM\EntityManagerInterface;
  5. use FOS\CKEditorBundle\Form\Type\CKEditorType;
  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\Form\Type\ModelListType;
  11. use Sonata\AdminBundle\Show\ShowMapper;
  12. use Sonata\Form\Type\CollectionType;
  13. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  14. class ProductAdmin extends AbstractAdmin
  15. {
  16.     protected $datagridValues = array(
  17.         '_page'       => 1,
  18.         '_sort_order' => 'ASC',
  19.         '_sort_by'    => 'id',
  20.     );
  21.     private $entityManager;
  22.     public function __construct(?string $code null, ?string $class null, ?string $baseControllerName nullEntityManagerInterface $entityManager null)
  23.     {
  24.         $this->entityManager $entityManager;
  25.         parent::__construct($code$class$baseControllerName);
  26.     }
  27.     protected function configureDatagridFilters(DatagridMapper $datagridMapper): void
  28.     {
  29.         $datagridMapper
  30.             ->add('name'null, ['label' => 'Nombre'])
  31.             ->add('categories'null, ['label' => 'Categorías'])
  32.         ;
  33.     }
  34.     protected function configureListFields(ListMapper $listMapper): void
  35.     {
  36.         $listMapper
  37.             ->add('id')
  38.             ->addIdentifier('name'null, ['label' => 'Nombre'])
  39.             ->addIdentifier('categories'null, ['label' => 'Categorías'])
  40.             ->add('public'null, ['label' => '¿Publicado?''editable' => true])
  41.             ->addIdentifier('create_at'null, ['label' => 'Creado el']);
  42.     }
  43.     protected function configureFormFields(FormMapper $formMapper): void
  44.     {
  45.         $formMapper
  46.             ->tab('General')
  47.             ->with('')
  48.                 ->add('public'null, ['label' => '¿Publicado?'])
  49.                 ->add('name'null, ['label' => 'Nombre'])
  50.                 ->add('categories'null, ['label' => 'Categorías'])
  51.                 ->add('description'CKEditorType::class, ['label' => 'Descripción''required' => false])
  52.                 ->add('recommended_uses'CKEditorType::class, ['label' => 'Usos Recomendados''required' => false])
  53.                 ->add('uses'CKEditorType::class, ['label' => 'Usos''required' => false])
  54.                 ->add('image'ModelListType::class, ['label' => 'Imagen'], ['link_parameters' => ['context' => 'default''provider' => 'sonata.media.provider.image']])
  55.                 ->add('image_cover'ModelListType::class, ['label' => 'Imagen Portada'], ['link_parameters' => ['context' => 'default''provider' => 'sonata.media.provider.image']])
  56.                 ->add('video'ModelListType::class, ['label' => 'Video'], ['link_parameters' => ['context' => 'video']])
  57.                 ->add('video_image'ModelListType::class, ['label' => 'Imagen Video'], ['link_parameters' => ['context' => 'default''provider' => 'sonata.media.provider.image']])
  58.                 ->add('packed_colors'null, ['label' => 'Colores Empacados'])
  59.                 ->add('link_mp'null, ['label' => 'Enlace Marketplace'])
  60.             ->end()
  61.             ->end()
  62.             ->tab('Colores')
  63.             ->with('')
  64.             ->add('colors'CollectionType::class, array(
  65.                 'by_reference' => false,
  66.                 'label'        => 'Colores',
  67.             ),    array(
  68.                       'edit'   => 'inline',
  69.                       'inline' => 'table',
  70.                       'order'  => 'ASC'
  71.                   ))
  72.             ->end()
  73.             ->end()
  74.             ->tab('Filtros')
  75.             ->with('')
  76.             ->add('filters'CollectionType::class, array(
  77.                 'by_reference' => false,
  78.                 'label'        => 'Filtros',
  79.             ),    array(
  80.                       'edit'   => 'inline',
  81.                       'inline' => 'table',
  82.                       //'sortable' => 'position',
  83.                       'order'  => 'ASC'
  84.                   ))
  85.             ->end()
  86.             ->end()
  87.             ->tab('Aplicación')
  88.             ->with('')
  89.                 ->add('conditions'null, ['label' => 'Colores'])
  90.                 ->add('dilution'null, ['label' => 'Diluyente'])
  91.                 ->add('tools'null, ['label' => 'Aplicación'])
  92.                 ->add('layers'null, ['label' => 'Rendimiento'])
  93.             ->end()
  94.             ->end()
  95.             ->tab('Secado')
  96.             ->with('')
  97.                 ->add('touch_drying'null, ['label' => 'Formato'])
  98.                 ->add('repaint_drying'null, ['label' => 'Tipo de superficie'])
  99.                 ->add('final_drying'null, ['label' => 'Terminación'])
  100.                 ->add('drying_time'null, ['label' => 'Tiempo de Secado'])
  101.             ->end()
  102.             ->end()
  103.             ->tab('Documentos')
  104.             ->with('')
  105.                 ->add('data_sheet'null, ['label' => 'Ficha técnica'])
  106.                 ->add('safety_sheet'null, ['label' => 'Hoja de Seguridad'])
  107.                 ->add('safety_sheet_cb'null, ['label' => 'Hoja de Seguridad C/B'])
  108.                 ->add('transport_sheet'null, ['label' => 'Hoja de Transporte'])
  109.             ->end()
  110.             ->end()
  111.             ;
  112.         if ($this->isCurrentRoute('edit')) {
  113.             $formMapper
  114.                 ->tab('Seo')
  115.                 ->with('')
  116.                 ->add('seo.title'null, ['label' => 'Titulo'])
  117.                 ->add('seo.keywords'null, ['label' => 'Palabras claves'])
  118.                 ->add('seo.description'TextareaType::class, ['label' => 'Descripción''required' => false])
  119.                 ->add('seo.share_image'ModelListType::class, ['label' => 'Imagen para compartir''required' => false], ['link_parameters' => ['context' => 'default''provider' => 'sonata.media.provider.image',]])
  120.                 ->end()
  121.                 ->end();
  122.         }
  123.     }
  124.     protected function configureShowFields(ShowMapper $showMapper): void
  125.     {
  126.         $showMapper
  127.             ->add('id')
  128.             ->add('name'null, ['label' => 'Nombre'])
  129.             ->add('create_at'null, ['label' => 'Creado el']);
  130.     }
  131.     /*public function getExportFields()
  132.     {
  133.         return array(
  134.             'Nombre'    => 'name',
  135.             'Acción'    => 'action',
  136.             'Usuario'   => 'user',
  137.             'Categoría' => 'kind',
  138.             'Creado el' => 'create_at',
  139.         );
  140.     }*/
  141.     public function prePersist($entity): void
  142.     {
  143.         $em $this->entityManager;
  144.         $seo = new Seo();
  145.         $seo->setTitle($entity->getName());
  146.         $em->persist($seo);
  147.         $em->flush($seo);
  148.         $entity->setSeo($seo);
  149.     }
  150. }