src/Infraestructure/Admin/MetadataCustomRegistroAdmin.php line 23

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Infraestructure\Admin;
  4. use App\Domain\Entity\MetadataExpedienteCabecera;
  5. use App\Shared\Infrastructure\Form\Type\JsonEditorType;
  6. use App\Shared\Infrastructure\JsonForm\Service\LoadDataSchemaJsonService;
  7. use Knp\Menu\ItemInterface;
  8. use Sonata\AdminBundle\Admin\AbstractAdmin;
  9. use Sonata\AdminBundle\Admin\AdminInterface;
  10. use Sonata\AdminBundle\Datagrid\DatagridMapper;
  11. use Sonata\AdminBundle\Datagrid\ListMapper;
  12. use Sonata\AdminBundle\Form\FormMapper;
  13. use Sonata\AdminBundle\Form\Type\AdminType;
  14. use Sonata\AdminBundle\Show\ShowMapper;
  15. use Sonata\Form\Type\CollectionType;
  16. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  17. final class MetadataCustomRegistroAdmin extends AbstractAdmin
  18. {
  19.     public function __construct(
  20.         ?string $code = null,
  21.         ?string $class = null,
  22.         ?string $baseControllerName = null,
  23.         private LoadDataSchemaJsonService $dataSchemaJsonService
  24.     )
  25.     {
  26.         parent::__construct($code, $class, $baseControllerName);
  27.     }
  28.     protected function configureDatagridFilters(DatagridMapper $filter): void
  29.     {   }
  30.     protected function configureListFields(ListMapper $list): void
  31.     {
  32.         $this->setTranslationDomain('metadataCustomRegistroAdmin');
  33.         
  34.         $list
  35.             ->add('key', null, [
  36.                 'label' => 'list.metadata_custom_registro.label.key',
  37.             ])
  38.             ->add('nombre', null, [
  39.                 'label' => 'list.metadata_custom_registro.label.nombre',
  40.             ])
  41.             ->add(ListMapper::NAME_ACTIONS, null, [
  42.                 'label' => false,
  43.                 'actions' => [
  44.                     'edit' => [],
  45.                     'delete' => [],
  46.                 ],
  47.                 'header_style' => 'width: 85px',
  48.             ]);
  49.     }
  50.     protected function configureFormFields(FormMapper $form): void
  51.     {
  52.         $this->setTranslationDomain('metadataCustomRegistroAdmin');
  53.         $form
  54.             ->tab('tab.custom_registro.datos_generales', [
  55.                 'label' => 'form.metadata_custom_registro.tab.label.datos_generales'
  56.             ])
  57.                 ->with('with.custom_registro.datos_generales')
  58.                     ->add('key', null, [
  59.                         'label' => 'form.metadata_custom_registro.label.key',
  60.                     ])
  61.                     ->add('nombre', null, [
  62.                         'label' => 'form.metadata_custom_registro.label.nombre',
  63.                     ])
  64.                     ->add('descripcion', null, [
  65.                         'label' => 'form.metadata_custom_registro.label.descripcion'
  66.                     ])
  67.                     ->add('schema', JsonEditorType::class, [
  68.                         'label' => 'form.metadata_custom_registro.label.schema',
  69.                         'mode' => 'tree',
  70.                         'schema' => $this->generateSchema()
  71.                     ])
  72.                 ->end()
  73.             ->end()
  74.             ->tab('tab.custom_registro.handlers', [
  75.                 'label' => 'form.metadata_custom_registro.tab.label.handlers'
  76.             ])
  77.                 ->with('with.custom_registro.handlers')
  78.                     ->add('handlers', CollectionType::class, [
  79.                         'label' => false,
  80.                         'required' => false,
  81.                         'by_reference' => false,
  82.                         'btn_add' => 'label.add',
  83.                         'type_options' => [
  84.                             'delete' => false
  85.                         ],
  86.                         'attr' => [
  87.                             'data-collapse' => true,
  88.                         ],
  89.                         'row_attr' => [ 'class' => 'metadata_custom_registro-handlers']
  90.                     ],[
  91.                         'edit' => 'inline',
  92.                         'inline' => 'table',
  93.                         'sortable' => 'position',
  94.                         'attr' => ['class' => 'table-handler table-view-card table-handler-view-card table-view-multiple-card'],
  95.                     ])
  96.                 ->end()
  97.             ->end()
  98.             ->tab('tab.custom_registro.css', [
  99.                 'label' => 'form.metadata_custom_registro.tab.label.css'
  100.             ])
  101.                 ->with('with.custom_registro.css')
  102.                     ->add('css', TextareaType::class, [
  103.                         'label' => false,
  104.                         'attr' => [
  105.                             'class' => 'codemirror-css',
  106.                             'rows' => 20
  107.                         ]
  108.                     ])
  109.                 ->end()
  110.             ->end()
  111.             ->tab('tab.custom_registro.js', [
  112.                 'label' => 'form.metadata_custom_registro.tab.label.js'
  113.             ])
  114.                 ->with('with.custom_registro.js')
  115.                     ->add('js', TextareaType::class, [
  116.                         'label' => false,
  117.                         'attr' => [
  118.                             'class' => 'codemirror-js',
  119.                             'rows' => 20
  120.                         ]
  121.                     ])
  122.                 ->end()
  123.             ->end()
  124.             ->tab('tab.custom_registro.translator', [
  125.                 'label' => 'form.metadata_custom_registro.tab.label.translator'
  126.             ])
  127.                 ->with('with.custom_registro.translator')
  128.                     ->add('translations', TextareaType::class, [
  129.                         'label' => false,
  130.                         'attr' => [
  131.                             'class' => 'codemirror-xml',
  132.                             'rows' => 20
  133.                         ]
  134.                     ])
  135.                 ->end()
  136.             ->end()
  137.         ;
  138.     }
  139.     protected function configureShowFields(ShowMapper $show): void
  140.     {  }
  141.     private function generateSchema()
  142.     {
  143. //        $roles = $this->roleHierarchy->getReachableRoleNames(["ROLE_SUPER_ADMIN"]);
  144. //        $entities = str_replace('\\', '\\\\', ClassUtils::getClassesInNamespace('App\\Domain\\Entity', getcwd()."/../src/Domain/Entity"));
  145. //        $namers = $this->vichUploadJsonMappingNamer;
  146. //        $directoriesNamer = $this->vichUploadJsonMappingDirectoriesNamer;
  147. //
  148.         $json = file_get_contents(getcwd()."/../src/Infraestructure/Schemas/json-schema-draft-07.json");
  149. //
  150. //        $jsonRoles = str_replace('@ROLES', implode('","', $roles), $json);
  151. //        $jsonRolesEntities = str_replace('@ENTITIES', implode('","', $entities), $jsonRoles);
  152. //        $jsonRolesEntitiesNamers = str_replace('@NAMERS', implode('","', $namers), $jsonRolesEntities);
  153. //        $jsonRolesEntitiesNamersDirectories = str_replace('@DIRECTORIES_NAMER', implode('","', $directoriesNamer), $jsonRolesEntitiesNamers);
  154.         $json = $this->dataSchemaJsonService->__invoke($json);
  155.         return json_decode($json, true);
  156.     }
  157. }