<?php
declare(strict_types=1);
namespace App\Infraestructure\Admin;
use App\Domain\Entity\MetadataExpedienteCabecera;
use App\Shared\Infrastructure\Form\Type\JsonEditorType;
use App\Shared\Infrastructure\JsonForm\Service\LoadDataSchemaJsonService;
use Knp\Menu\ItemInterface;
use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Admin\AdminInterface;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Form\Type\AdminType;
use Sonata\AdminBundle\Show\ShowMapper;
use Sonata\Form\Type\CollectionType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
final class MetadataCustomRegistroAdmin extends AbstractAdmin
{
public function __construct(
?string $code = null,
?string $class = null,
?string $baseControllerName = null,
private LoadDataSchemaJsonService $dataSchemaJsonService
)
{
parent::__construct($code, $class, $baseControllerName);
}
protected function configureDatagridFilters(DatagridMapper $filter): void
{ }
protected function configureListFields(ListMapper $list): void
{
$this->setTranslationDomain('metadataCustomRegistroAdmin');
$list
->add('key', null, [
'label' => 'list.metadata_custom_registro.label.key',
])
->add('nombre', null, [
'label' => 'list.metadata_custom_registro.label.nombre',
])
->add(ListMapper::NAME_ACTIONS, null, [
'label' => false,
'actions' => [
'edit' => [],
'delete' => [],
],
'header_style' => 'width: 85px',
]);
}
protected function configureFormFields(FormMapper $form): void
{
$this->setTranslationDomain('metadataCustomRegistroAdmin');
$form
->tab('tab.custom_registro.datos_generales', [
'label' => 'form.metadata_custom_registro.tab.label.datos_generales'
])
->with('with.custom_registro.datos_generales')
->add('key', null, [
'label' => 'form.metadata_custom_registro.label.key',
])
->add('nombre', null, [
'label' => 'form.metadata_custom_registro.label.nombre',
])
->add('descripcion', null, [
'label' => 'form.metadata_custom_registro.label.descripcion'
])
->add('schema', JsonEditorType::class, [
'label' => 'form.metadata_custom_registro.label.schema',
'mode' => 'tree',
'schema' => $this->generateSchema()
])
->end()
->end()
->tab('tab.custom_registro.handlers', [
'label' => 'form.metadata_custom_registro.tab.label.handlers'
])
->with('with.custom_registro.handlers')
->add('handlers', CollectionType::class, [
'label' => false,
'required' => false,
'by_reference' => false,
'btn_add' => 'label.add',
'type_options' => [
'delete' => false
],
'attr' => [
'data-collapse' => true,
],
'row_attr' => [ 'class' => 'metadata_custom_registro-handlers']
],[
'edit' => 'inline',
'inline' => 'table',
'sortable' => 'position',
'attr' => ['class' => 'table-handler table-view-card table-handler-view-card table-view-multiple-card'],
])
->end()
->end()
->tab('tab.custom_registro.css', [
'label' => 'form.metadata_custom_registro.tab.label.css'
])
->with('with.custom_registro.css')
->add('css', TextareaType::class, [
'label' => false,
'attr' => [
'class' => 'codemirror-css',
'rows' => 20
]
])
->end()
->end()
->tab('tab.custom_registro.js', [
'label' => 'form.metadata_custom_registro.tab.label.js'
])
->with('with.custom_registro.js')
->add('js', TextareaType::class, [
'label' => false,
'attr' => [
'class' => 'codemirror-js',
'rows' => 20
]
])
->end()
->end()
->tab('tab.custom_registro.translator', [
'label' => 'form.metadata_custom_registro.tab.label.translator'
])
->with('with.custom_registro.translator')
->add('translations', TextareaType::class, [
'label' => false,
'attr' => [
'class' => 'codemirror-xml',
'rows' => 20
]
])
->end()
->end()
;
}
protected function configureShowFields(ShowMapper $show): void
{ }
private function generateSchema()
{
// $roles = $this->roleHierarchy->getReachableRoleNames(["ROLE_SUPER_ADMIN"]);
// $entities = str_replace('\\', '\\\\', ClassUtils::getClassesInNamespace('App\\Domain\\Entity', getcwd()."/../src/Domain/Entity"));
// $namers = $this->vichUploadJsonMappingNamer;
// $directoriesNamer = $this->vichUploadJsonMappingDirectoriesNamer;
//
$json = file_get_contents(getcwd()."/../src/Infraestructure/Schemas/json-schema-draft-07.json");
//
// $jsonRoles = str_replace('@ROLES', implode('","', $roles), $json);
// $jsonRolesEntities = str_replace('@ENTITIES', implode('","', $entities), $jsonRoles);
// $jsonRolesEntitiesNamers = str_replace('@NAMERS', implode('","', $namers), $jsonRolesEntities);
// $jsonRolesEntitiesNamersDirectories = str_replace('@DIRECTORIES_NAMER', implode('","', $directoriesNamer), $jsonRolesEntitiesNamers);
$json = $this->dataSchemaJsonService->__invoke($json);
return json_decode($json, true);
}
}