diff --git a/composer.json b/composer.json index a3364523327..bd25c958a22 100644 --- a/composer.json +++ b/composer.json @@ -34,7 +34,7 @@ "symfony/asset": "^4.4", "symfony/config": "^4.4", "symfony/console": "^4.4", - "symfony/dependency-injection": "^4.4.3", + "symfony/dependency-injection": "^4.4.8", "symfony/doctrine-bridge": "^4.4", "symfony/event-dispatcher": "^4.4", "symfony/event-dispatcher-contracts": "^1.1 || ^2.0", diff --git a/src/DependencyInjection/SonataAdminExtension.php b/src/DependencyInjection/SonataAdminExtension.php index 0bf372dce0a..9bb814f3368 100644 --- a/src/DependencyInjection/SonataAdminExtension.php +++ b/src/DependencyInjection/SonataAdminExtension.php @@ -18,7 +18,7 @@ use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; -use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; +use Symfony\Component\DependencyInjection\Loader\PhpFileLoader; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\Form\Extension\Core\Type\ChoiceType as SymfonyChoiceType; use Symfony\Component\Form\Extension\Core\Type\DateTimeType as SymfonyDateTimeType; @@ -59,24 +59,24 @@ public function load(array $configs, ContainerBuilder $container) ]); } - $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); - $loader->load('actions.xml'); - $loader->load('block.xml'); - $loader->load('commands.xml'); - $loader->load('core.xml'); - $loader->load('event_listener.xml'); - $loader->load('form_types.xml'); - $loader->load('menu.xml'); - $loader->load('route.xml'); - $loader->load('twig.xml'); - $loader->load('validator.xml'); + $loader = new PhpFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); + $loader->load('actions.php'); + $loader->load('block.php'); + $loader->load('commands.php'); + $loader->load('core.php'); + $loader->load('event_listener.php'); + $loader->load('form_types.php'); + $loader->load('menu.php'); + $loader->load('route.php'); + $loader->load('twig.php'); + $loader->load('validator.php'); if (isset($bundles['MakerBundle'])) { - $loader->load('makers.xml'); + $loader->load('makers.php'); } if (isset($bundles['SonataExporterBundle'])) { - $loader->load('exporter.xml'); + $loader->load('exporter.php'); } $configuration = $this->getConfiguration($configs, $container); @@ -157,7 +157,7 @@ public function load(array $configs, ContainerBuilder $container) $container->setParameter('sonata.admin.configuration.security.admin_permissions', $config['security']['admin_permissions']); $container->setParameter('sonata.admin.configuration.security.object_permissions', $config['security']['object_permissions']); - $loader->load('security.xml'); + $loader->load('security.php'); $container->setParameter('sonata.admin.extension.map', $config['extensions']); @@ -272,10 +272,10 @@ private function replacePropertyAccessor(ContainerBuilder $container): void /** * NEXT_MAJOR: remove this method. */ - private function configureTwigTextExtension(ContainerBuilder $container, XmlFileLoader $loader, array $config): void + private function configureTwigTextExtension(ContainerBuilder $container, PhpFileLoader $loader, array $config): void { $container->setParameter('sonata.admin.configuration.legacy_twig_text_extension', $config['options']['legacy_twig_text_extension']); - $loader->load('twig_string.xml'); + $loader->load('twig_string.php'); if (false !== $config['options']['legacy_twig_text_extension']) { $container diff --git a/src/Resources/config/actions.php b/src/Resources/config/actions.php new file mode 100644 index 00000000000..9b111564e0f --- /dev/null +++ b/src/Resources/config/actions.php @@ -0,0 +1,70 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Sonata\AdminBundle\Action\AppendFormFieldElementAction; +use Sonata\AdminBundle\Action\DashboardAction; +use Sonata\AdminBundle\Action\GetShortObjectDescriptionAction; +use Sonata\AdminBundle\Action\RetrieveAutocompleteItemsAction; +use Sonata\AdminBundle\Action\RetrieveFormFieldElementAction; +use Sonata\AdminBundle\Action\SearchAction; +use Sonata\AdminBundle\Action\SetObjectFieldValueAction; +use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; +use function Symfony\Component\DependencyInjection\Loader\Configurator\ref; + +return static function (ContainerConfigurator $containerConfigurator): void { + $services = $containerConfigurator->services(); + + $services->set(DashboardAction::class, DashboardAction::class) + ->public() + ->args([ + '%sonata.admin.configuration.dashboard_blocks%', + ref('sonata.admin.breadcrumbs_builder'), + ref('sonata.admin.global_template_registry'), + ref('sonata.admin.pool'), + ref('twig'), + ]); + + $services->set(SearchAction::class, SearchAction::class) + ->public() + ->args([ + ref('sonata.admin.pool'), + ref('sonata.admin.search.handler'), + ref('sonata.admin.global_template_registry'), + ref('sonata.admin.breadcrumbs_builder'), + ref('twig'), + ]); + + $services->set('sonata.admin.action.append_form_field_element', AppendFormFieldElementAction::class) + ->public() + ->args([ + ref('twig'), + ref('sonata.admin.pool'), + ref('sonata.admin.helper'), + ]); + + $services->set('sonata.admin.action.retrieve_form_field_element', RetrieveFormFieldElementAction::class) + ->public() + ->args([ref('twig'), ref('sonata.admin.pool'), ref('sonata.admin.helper')]); + + $services->set('sonata.admin.action.get_short_object_description', GetShortObjectDescriptionAction::class) + ->public() + ->args([ref('twig'), ref('sonata.admin.pool')]); + + $services->set('sonata.admin.action.set_object_field_value', SetObjectFieldValueAction::class) + ->public() + ->args([ref('twig'), ref('sonata.admin.pool'), ref('validator')]); + + $services->set('sonata.admin.action.retrieve_autocomplete_items', RetrieveAutocompleteItemsAction::class) + ->public() + ->args([ref('sonata.admin.pool')]); +}; diff --git a/src/Resources/config/block.php b/src/Resources/config/block.php new file mode 100644 index 00000000000..02be7a77499 --- /dev/null +++ b/src/Resources/config/block.php @@ -0,0 +1,48 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Sonata\AdminBundle\Block\AdminListBlockService; +use Sonata\AdminBundle\Block\AdminSearchBlockService; +use Sonata\AdminBundle\Block\AdminStatsBlockService; +use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; +use function Symfony\Component\DependencyInjection\Loader\Configurator\ref; + +return static function (ContainerConfigurator $containerConfigurator): void { + $services = $containerConfigurator->services(); + + $services->set('sonata.admin.block.admin_list', AdminListBlockService::class) + ->public() + ->tag('sonata.block', []) + ->args([ + ref('twig'), + ref('sonata.admin.pool'), + ref('sonata.admin.global_template_registry'), + ]); + + $services->set('sonata.admin.block.search_result', AdminSearchBlockService::class) + ->public() + ->tag('sonata.block', []) + ->args([ + ref('twig'), + ref('sonata.admin.pool'), + ref('sonata.admin.search.handler'), + ]); + + $services->set('sonata.admin.block.stats', AdminStatsBlockService::class) + ->public() + ->tag('sonata.block', []) + ->args([ + ref('twig'), + ref('sonata.admin.pool'), + ]); +}; diff --git a/src/Resources/config/commands.php b/src/Resources/config/commands.php new file mode 100644 index 00000000000..3f5e367ae2f --- /dev/null +++ b/src/Resources/config/commands.php @@ -0,0 +1,50 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Sonata\AdminBundle\Command\CreateClassCacheCommand; +use Sonata\AdminBundle\Command\ExplainAdminCommand; +use Sonata\AdminBundle\Command\GenerateObjectAclCommand; +use Sonata\AdminBundle\Command\ListAdminCommand; +use Sonata\AdminBundle\Command\SetupAclCommand; +use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; +use function Symfony\Component\DependencyInjection\Loader\Configurator\ref; + +return static function (ContainerConfigurator $containerConfigurator): void { + $services = $containerConfigurator->services(); + + $services->set(CreateClassCacheCommand::class, CreateClassCacheCommand::class) + ->public() + ->tag('console.command', ['command' => 'cache:create-cache-class']) + ->deprecate('The "%service_id%" service is deprecated since version sonata-project/admin-bundle 3.39.0 and will be removed in 4.0.') + ->args(['%kernel.cache_dir%', '%kernel.debug%']); + + $services->set(ExplainAdminCommand::class, ExplainAdminCommand::class) + ->public() + ->tag('console.command') + ->args([ref('sonata.admin.pool'), ref('validator')]); + + $services->set(GenerateObjectAclCommand::class, GenerateObjectAclCommand::class) + ->public() + ->tag('console.command') + ->args([ref('sonata.admin.pool'), [], ref('doctrine')->nullOnInvalid()]); + + $services->set(ListAdminCommand::class, ListAdminCommand::class) + ->public() + ->tag('console.command') + ->args([ref('sonata.admin.pool')]); + + $services->set(SetupAclCommand::class, SetupAclCommand::class) + ->public() + ->tag('console.command') + ->args([ref('sonata.admin.pool'), ref('sonata.admin.manipulator.acl.admin')]); +}; diff --git a/src/Resources/config/core.php b/src/Resources/config/core.php new file mode 100644 index 00000000000..0e3f888e026 --- /dev/null +++ b/src/Resources/config/core.php @@ -0,0 +1,175 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Sonata\AdminBundle\Admin\AdminHelper; +use Sonata\AdminBundle\Admin\BreadcrumbsBuilder; +use Sonata\AdminBundle\Admin\BreadcrumbsBuilderInterface; +use Sonata\AdminBundle\Admin\Extension\LockExtension; +use Sonata\AdminBundle\Admin\Pool; +use Sonata\AdminBundle\Controller\HelperController; +use Sonata\AdminBundle\Event\AdminEventExtension; +use Sonata\AdminBundle\Export\Exporter; +use Sonata\AdminBundle\Filter\FilterFactory; +use Sonata\AdminBundle\Filter\FilterFactoryInterface; +use Sonata\AdminBundle\Filter\Persister\FilterPersisterInterface; +use Sonata\AdminBundle\Filter\Persister\SessionFilterPersister; +use Sonata\AdminBundle\Model\AuditManager; +use Sonata\AdminBundle\Model\AuditManagerInterface; +use Sonata\AdminBundle\Route\AdminPoolLoader; +use Sonata\AdminBundle\Search\SearchHandler; +use Sonata\AdminBundle\Templating\MutableTemplateRegistryInterface; +use Sonata\AdminBundle\Templating\TemplateRegistry; +use Sonata\AdminBundle\Translator\BCLabelTranslatorStrategy; +use Sonata\AdminBundle\Translator\Extractor\AdminExtractor; +use Sonata\AdminBundle\Translator\Extractor\JMSTranslatorBundle\AdminExtractor as DeprecatedAdminExtractor; +use Sonata\AdminBundle\Translator\FormLabelTranslatorStrategy; +use Sonata\AdminBundle\Translator\LabelTranslatorStrategyInterface; +use Sonata\AdminBundle\Translator\NativeLabelTranslatorStrategy; +use Sonata\AdminBundle\Translator\NoopLabelTranslatorStrategy; +use Sonata\AdminBundle\Translator\UnderscoreLabelTranslatorStrategy; +use Sonata\AdminBundle\Twig\GlobalVariables; +use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; +use function Symfony\Component\DependencyInjection\Loader\Configurator\ref; + +return static function (ContainerConfigurator $containerConfigurator): void { + $services = $containerConfigurator->services(); + + $services->set('sonata.admin.pool', Pool::class) + ->public() + ->args([ref('service_container'), '', '', [], ref('property_accessor')]) + ->call('setTemplateRegistry', [ref('sonata.admin.global_template_registry')]); + + $services->set('sonata.admin.route_loader', AdminPoolLoader::class) + ->public() + ->tag('routing.loader', []) + ->args([ref('sonata.admin.pool'), '', ref('service_container')]); + + $services->set('sonata.admin.helper', AdminHelper::class) + ->public() + ->args([ref('sonata.admin.pool')]); + + $services->set('sonata.admin.builder.filter.factory', FilterFactory::class) + ->public() + ->args([ref('service_container'), '']); + + $services->set('sonata.admin.breadcrumbs_builder', BreadcrumbsBuilder::class) + ->public() + ->args(['%sonata.admin.configuration.breadcrumbs%']); + + $services->set('sonata.admin.label.strategy.bc', BCLabelTranslatorStrategy::class) + ->public(); + + $services->set('sonata.admin.label.strategy.native', NativeLabelTranslatorStrategy::class) + ->public(); + + $services->set('sonata.admin.label.strategy.noop', NoopLabelTranslatorStrategy::class) + ->public(); + + $services->set('sonata.admin.label.strategy.underscore', UnderscoreLabelTranslatorStrategy::class) + ->public(); + + $services->set('sonata.admin.label.strategy.form_component', FormLabelTranslatorStrategy::class) + ->public(); + + $services->set('sonata.admin.translator.extractor.jms_translator_bundle', DeprecatedAdminExtractor::class) + ->public() + ->tag('jms_translation.extractor', ['alias' => 'sonata_admin']) + ->deprecate('The service "%service_id%" is deprecated in favor of the "Sonata\AdminBundle\Translator\Extractor\AdminExtractor" service since version 3.72 and will be removed in 4.0.') + ->args([ref('sonata.admin.pool'), ref('logger')->nullOnInvalid()]) + ->call('setBreadcrumbsBuilder', [ref('sonata.admin.breadcrumbs_builder')]); + + $services->set(AdminExtractor::class) + ->tag('translation.extractor', ['alias' => 'sonata_admin']) + ->args([ref('sonata.admin.pool'), ref('sonata.admin.breadcrumbs_builder')]); + + $services->set('sonata.admin.controller.admin', HelperController::class) + ->public() + ->deprecate('The controller service "%service_id%" is deprecated in favor of several action services since version 3.38.0 and will be removed in 4.0.') + ->args([ref('twig'), ref('sonata.admin.pool'), ref('sonata.admin.helper'), ref('validator')]); + + $services->set('sonata.admin.audit.manager', AuditManager::class) + ->public() + ->args([ref('service_container')]); + + $services->set('sonata.admin.exporter', Exporter::class) + ->public() + ->deprecate('The service "%service_id%" is deprecated in favor of the "sonata.exporter.exporter" service since version 3.14 and will be removed in 4.0.'); + + $services->set('sonata.admin.search.handler', SearchHandler::class) + ->public() + ->args([ref('sonata.admin.pool'), '%sonata.admin.configuration.global_search.case_sensitive%']); + + $services->set('sonata.admin.event.extension', AdminEventExtension::class) + ->public() + ->tag('sonata.admin.extension', ['global' => true]) + ->args([ref('event_dispatcher')]); + + $services->set('sonata.admin.lock.extension', LockExtension::class) + ->public() + ->tag('sonata.admin.extension', ['global' => true]); + + $services->set('sonata.admin.twig.global', GlobalVariables::class) + ->public() + ->args([ref('sonata.admin.pool'), '%sonata.admin.configuration.mosaic_background%']); + + $services->set('sonata.admin.filter_persister.session', SessionFilterPersister::class) + ->args([ref('session')]); + + $services->set('sonata.admin.global_template_registry', TemplateRegistry::class) + ->public() + ->args(['%sonata.admin.configuration.templates%']); + + $services->alias(Pool::class, 'sonata.admin.pool'); + + $services->alias(AdminPoolLoader::class, 'sonata.admin.route_loader'); + + $services->alias(AdminHelper::class, 'sonata.admin.helper'); + + $services->alias(FilterFactory::class, 'sonata.admin.builder.filter.factory'); + + $services->alias(FilterFactoryInterface::class, 'sonata.admin.builder.filter.factory'); + + $services->alias(BreadcrumbsBuilder::class, 'sonata.admin.breadcrumbs_builder'); + + $services->alias(BreadcrumbsBuilderInterface::class, 'sonata.admin.breadcrumbs_builder'); + + $services->alias(BCLabelTranslatorStrategy::class, 'sonata.admin.label.strategy.bc'); + + $services->alias(NativeLabelTranslatorStrategy::class, 'sonata.admin.label.strategy.native'); + + $services->alias(LabelTranslatorStrategyInterface::class, 'sonata.admin.label.strategy.native'); + + $services->alias(NoopLabelTranslatorStrategy::class, 'sonata.admin.label.strategy.noop'); + + $services->alias(UnderscoreLabelTranslatorStrategy::class, 'sonata.admin.label.strategy.underscore'); + + $services->alias(FormLabelTranslatorStrategy::class, 'sonata.admin.label.strategy.form_component'); + + $services->alias(AuditManager::class, 'sonata.admin.audit.manager'); + + $services->alias(AuditManagerInterface::class, 'sonata.admin.audit.manager'); + + $services->alias(SearchHandler::class, 'sonata.admin.search.handler'); + + $services->alias(AdminEventExtension::class, 'sonata.admin.event.extension'); + + $services->alias(GlobalVariables::class, 'sonata.admin.twig.global'); + + $services->alias(SessionFilterPersister::class, 'sonata.admin.filter_persister.session'); + + $services->alias(FilterPersisterInterface::class, 'sonata.admin.filter_persister.session'); + + $services->alias(TemplateRegistry::class, 'sonata.admin.global_template_registry'); + + $services->alias(MutableTemplateRegistryInterface::class, 'sonata.admin.global_template_registry'); +}; diff --git a/src/Resources/config/event_listener.php b/src/Resources/config/event_listener.php new file mode 100644 index 00000000000..c28a0cce3d4 --- /dev/null +++ b/src/Resources/config/event_listener.php @@ -0,0 +1,24 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Sonata\AdminBundle\EventListener\AssetsInstallCommandListener; +use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; +use function Symfony\Component\DependencyInjection\Loader\Configurator\ref; + +return static function (ContainerConfigurator $containerConfigurator): void { + $services = $containerConfigurator->services(); + + $services->set(AssetsInstallCommandListener::class) + ->tag('kernel.event_listener', ['event' => 'console.terminate', 'method' => 'copySonataCoreBundleAssets']) + ->args([ref('filesystem'), '%kernel.project_dir%']); +}; diff --git a/src/Resources/config/exporter.php b/src/Resources/config/exporter.php new file mode 100644 index 00000000000..b83236034d0 --- /dev/null +++ b/src/Resources/config/exporter.php @@ -0,0 +1,24 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Sonata\AdminBundle\Bridge\Exporter\AdminExporter; +use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; +use function Symfony\Component\DependencyInjection\Loader\Configurator\ref; + +return static function (ContainerConfigurator $containerConfigurator): void { + $services = $containerConfigurator->services(); + + $services->set('sonata.admin.admin_exporter', AdminExporter::class) + ->public() + ->args([ref('sonata.exporter.exporter')]); +}; diff --git a/src/Resources/config/form_types.php b/src/Resources/config/form_types.php new file mode 100644 index 00000000000..fc0a3a9a76d --- /dev/null +++ b/src/Resources/config/form_types.php @@ -0,0 +1,120 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Sonata\AdminBundle\Form\Extension\ChoiceTypeExtension; +use Sonata\AdminBundle\Form\Extension\Field\Type\FormTypeFieldExtension; +use Sonata\AdminBundle\Form\Extension\Field\Type\MopaCompatibilityTypeFieldExtension; +use Sonata\AdminBundle\Form\Type\AdminType; +use Sonata\AdminBundle\Form\Type\ChoiceFieldMaskType; +use Sonata\AdminBundle\Form\Type\CollectionType; +use Sonata\AdminBundle\Form\Type\Filter\ChoiceType; +use Sonata\AdminBundle\Form\Type\Filter\DateRangeType; +use Sonata\AdminBundle\Form\Type\Filter\DateTimeRangeType; +use Sonata\AdminBundle\Form\Type\Filter\DateTimeType; +use Sonata\AdminBundle\Form\Type\Filter\DateType; +use Sonata\AdminBundle\Form\Type\Filter\DefaultType; +use Sonata\AdminBundle\Form\Type\Filter\NumberType; +use Sonata\AdminBundle\Form\Type\ModelAutocompleteType; +use Sonata\AdminBundle\Form\Type\ModelHiddenType; +use Sonata\AdminBundle\Form\Type\ModelListType; +use Sonata\AdminBundle\Form\Type\ModelReferenceType; +use Sonata\AdminBundle\Form\Type\ModelType; +use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; +use function Symfony\Component\DependencyInjection\Loader\Configurator\ref; +use Symfony\Component\Form\Extension\Core\Type\ChoiceType as SymfonyChoiceType; +use Symfony\Component\Form\Extension\Core\Type\FormType; + +return static function (ContainerConfigurator $containerConfigurator): void { + $services = $containerConfigurator->services(); + + $services->set('sonata.admin.form.type.admin', AdminType::class) + ->public() + ->tag('form.type', ['alias' => 'sonata_type_admin']) + ->args([ref('sonata.admin.helper')]); + + $services->set('sonata.admin.form.type.model_choice', ModelType::class) + ->public() + ->tag('form.type', ['alias' => 'sonata_type_model']) + ->args([ref('property_accessor')]); + + $services->set('sonata.admin.form.type.model_list', ModelListType::class) + ->public() + ->tag('form.type', ['alias' => 'sonata_type_model_list']); + + $services->set('sonata.admin.form.type.model_reference', ModelReferenceType::class) + ->public() + ->tag('form.type', ['alias' => 'sonata_type_model_reference']); + + $services->set('sonata.admin.form.type.model_hidden', ModelHiddenType::class) + ->public() + ->tag('form.type', ['alias' => 'sonata_type_model_hidden']); + + $services->set('sonata.admin.form.type.model_autocomplete', ModelAutocompleteType::class) + ->public() + ->tag('form.type', ['alias' => 'sonata_type_model_autocomplete']); + + $services->set('sonata.admin.form.type.collection', CollectionType::class) + ->public() + ->tag('form.type', ['alias' => 'sonata_type_native_collection']); + + $services->set('sonata.admin.doctrine_orm.form.type.choice_field_mask', ChoiceFieldMaskType::class) + ->public() + ->tag('form.type', ['alias' => 'sonata_type_choice_field_mask']); + + $services->set('sonata.admin.form.extension.field', FormTypeFieldExtension::class) + ->public() + ->tag('form.type_extension', ['alias' => 'form', 'extended_type' => FormType::class, 'extended-type' => FormType::class]) + ->args(['', '']); + + $services->set('sonata.admin.form.extension.field.mopa', MopaCompatibilityTypeFieldExtension::class) + ->public() + ->tag('form.type_extension', ['alias' => 'form', 'extended_type' => FormType::class, 'extended-type' => FormType::class]); + + $services->set('sonata.admin.form.extension.choice', ChoiceTypeExtension::class) + ->public() + ->tag('form.type_extension', ['alias' => 'choice', 'extended_type' => SymfonyChoiceType::class, 'extended-type' => ChoiceType::class]); + + $services->set('sonata.admin.form.filter.type.number', NumberType::class) + ->public() + ->tag('form.type', ['alias' => 'sonata_type_filter_number']) + ->args([ref('translator')]); + + $services->set('sonata.admin.form.filter.type.choice', ChoiceType::class) + ->public() + ->tag('form.type', ['alias' => 'sonata_type_filter_choice']) + ->args([ref('translator')]); + + $services->set('sonata.admin.form.filter.type.default', DefaultType::class) + ->public() + ->tag('form.type', ['alias' => 'sonata_type_filter_default']); + + $services->set('sonata.admin.form.filter.type.date', DateType::class) + ->public() + ->tag('form.type', ['alias' => 'sonata_type_filter_date']) + ->args([ref('translator')]); + + $services->set('sonata.admin.form.filter.type.daterange', DateRangeType::class) + ->public() + ->tag('form.type', ['alias' => 'sonata_type_filter_date_range']) + ->args([ref('translator')]); + + $services->set('sonata.admin.form.filter.type.datetime', DateTimeType::class) + ->public() + ->tag('form.type', ['alias' => 'sonata_type_filter_datetime']) + ->args([ref('translator')]); + + $services->set('sonata.admin.form.filter.type.datetime_range', DateTimeRangeType::class) + ->public() + ->tag('form.type', ['alias' => 'sonata_type_filter_datetime_range']) + ->args([ref('translator')]); +}; diff --git a/src/Resources/config/makers.php b/src/Resources/config/makers.php new file mode 100644 index 00000000000..c19edca17da --- /dev/null +++ b/src/Resources/config/makers.php @@ -0,0 +1,23 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Sonata\AdminBundle\Maker\AdminMaker; +use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; + +return static function (ContainerConfigurator $containerConfigurator): void { + $services = $containerConfigurator->services(); + + $services->set('sonata.admin.maker', AdminMaker::class) + ->tag('maker.command') + ->args(['%kernel.project_dir%', []]); +}; diff --git a/src/Resources/config/menu.php b/src/Resources/config/menu.php new file mode 100644 index 00000000000..b41ba050768 --- /dev/null +++ b/src/Resources/config/menu.php @@ -0,0 +1,61 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Knp\Menu\MenuItem; +use Sonata\AdminBundle\Menu\Matcher\Voter\ActiveVoter; +use Sonata\AdminBundle\Menu\Matcher\Voter\AdminVoter; +use Sonata\AdminBundle\Menu\Matcher\Voter\ChildrenVoter; +use Sonata\AdminBundle\Menu\MenuBuilder; +use Sonata\AdminBundle\Menu\Provider\GroupMenuProvider; +use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; +use function Symfony\Component\DependencyInjection\Loader\Configurator\ref; + +return static function (ContainerConfigurator $containerConfigurator): void { + $services = $containerConfigurator->services(); + + $services->set('sonata.admin.menu_builder', MenuBuilder::class) + ->public() + ->args([ + ref('sonata.admin.pool'), + ref('knp_menu.factory'), + ref('knp_menu.menu_provider'), + ref('event_dispatcher'), + ]); + + $services->set('sonata.admin.sidebar_menu', MenuItem::class) + ->public() + ->tag('knp_menu.menu', ['alias' => 'sonata_admin_sidebar']) + ->factory([ref('sonata.admin.menu_builder'), 'createSidebarMenu']); + + $services->set('sonata.admin.menu.group_provider', GroupMenuProvider::class) + ->tag('knp_menu.provider') + ->args([ + ref('knp_menu.factory'), + ref('sonata.admin.pool'), + ref('security.authorization_checker'), + ]); + + $services->set('sonata.admin.menu.matcher.voter.admin', AdminVoter::class) + ->public() + ->tag('knp_menu.voter') + ->args([ref('request_stack')]); + + $services->set('sonata.admin.menu.matcher.voter.children', ChildrenVoter::class) + ->public() + ->deprecate('The "%service_id%" service is deprecated since 3.28 and will be removed in 4.0.') + ->args([ref('knp_menu.matcher')]); + + $services->set('sonata.admin.menu.matcher.voter.active', ActiveVoter::class) + ->public() + ->tag('knp_menu.voter'); +}; diff --git a/src/Resources/config/route.php b/src/Resources/config/route.php new file mode 100644 index 00000000000..4697f1a3493 --- /dev/null +++ b/src/Resources/config/route.php @@ -0,0 +1,48 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Sonata\AdminBundle\Route\DefaultRouteGenerator; +use Sonata\AdminBundle\Route\PathInfoBuilder; +use Sonata\AdminBundle\Route\QueryStringBuilder; +use Sonata\AdminBundle\Route\RoutesCache; +use Sonata\AdminBundle\Route\RoutesCacheWarmUp; +use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; +use function Symfony\Component\DependencyInjection\Loader\Configurator\ref; + +return static function (ContainerConfigurator $containerConfigurator): void { + $services = $containerConfigurator->services(); + + $services->set('sonata.admin.route.path_info', PathInfoBuilder::class) + ->public() + ->args([ref('sonata.admin.audit.manager')]); + + $services->set('sonata.admin.route.query_string', QueryStringBuilder::class) + ->public() + ->args([ref('sonata.admin.audit.manager')]); + + $services->set('sonata.admin.route.default_generator', DefaultRouteGenerator::class) + ->public() + ->args([ref('router'), ref('sonata.admin.route.cache')]); + + $services->set('sonata.admin.route.cache', RoutesCache::class) + ->public() + ->args(['%kernel.cache_dir%/sonata/admin', '%kernel.debug%']); + + $services->set('sonata.admin.route.cache_warmup', RoutesCacheWarmUp::class) + ->public() + ->tag('kernel.cache_warmer', []) + ->args([ + ref('sonata.admin.route.cache'), + ref('sonata.admin.pool'), + ]); +}; diff --git a/src/Resources/config/security.php b/src/Resources/config/security.php new file mode 100644 index 00000000000..1f4a11e93da --- /dev/null +++ b/src/Resources/config/security.php @@ -0,0 +1,66 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Sonata\AdminBundle\Security\Acl\Permission\MaskBuilder; +use Sonata\AdminBundle\Security\Handler\AclSecurityHandler; +use Sonata\AdminBundle\Security\Handler\NoopSecurityHandler; +use Sonata\AdminBundle\Security\Handler\RoleSecurityHandler; +use Sonata\AdminBundle\Util\AdminAclManipulator; +use Sonata\AdminBundle\Util\AdminObjectAclManipulator; +use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; +use function Symfony\Component\DependencyInjection\Loader\Configurator\ref; + +return static function (ContainerConfigurator $containerConfigurator): void { + $parameters = $containerConfigurator->parameters(); + + $parameters->set('sonata.admin.security.handler.noop.class', NoopSecurityHandler::class); + + $parameters->set('sonata.admin.security.handler.role.class', RoleSecurityHandler::class); + + $parameters->set('sonata.admin.security.handler.acl.class', AclSecurityHandler::class); + + $parameters->set('sonata.admin.security.mask.builder.class', MaskBuilder::class); + + $parameters->set('sonata.admin.manipulator.acl.admin.class', AdminAclManipulator::class); + + $parameters->set('sonata.admin.object.manipulator.acl.admin.class', AdminObjectAclManipulator::class); + + $services = $containerConfigurator->services(); + + $services->set('sonata.admin.security.handler.noop', '%sonata.admin.security.handler.noop.class%'); + + $services->set('sonata.admin.security.handler.role', '%sonata.admin.security.handler.role.class%') + ->args([ + ref('security.authorization_checker'), + ['%sonata.admin.configuration.security.role_super_admin%'], + ]); + + $services->set('sonata.admin.security.handler.acl', '%sonata.admin.security.handler.acl.class%') + ->args([ + ref('security.token_storage'), + ref('security.authorization_checker'), + ref('security.acl.provider')->nullOnInvalid(), + '%sonata.admin.security.mask.builder.class%', + ['%sonata.admin.configuration.security.role_super_admin%'], + ]) + ->call('setAdminPermissions', ['%sonata.admin.configuration.security.admin_permissions%']) + ->call('setObjectPermissions', ['%sonata.admin.configuration.security.object_permissions%']); + + $services->set('sonata.admin.manipulator.acl.admin', '%sonata.admin.manipulator.acl.admin.class%') + ->public() + ->args(['%sonata.admin.security.mask.builder.class%']); + + $services->set('sonata.admin.object.manipulator.acl.admin', '%sonata.admin.object.manipulator.acl.admin.class%') + ->public() + ->args([ref('form.factory'), '%sonata.admin.security.mask.builder.class%']); +}; diff --git a/src/Resources/config/twig.php b/src/Resources/config/twig.php new file mode 100644 index 00000000000..8273cc0cde5 --- /dev/null +++ b/src/Resources/config/twig.php @@ -0,0 +1,60 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Sonata\AdminBundle\Twig\Extension\SonataAdminExtension; +use Sonata\AdminBundle\Twig\Extension\TemplateRegistryExtension; +use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; +use function Symfony\Component\DependencyInjection\Loader\Configurator\ref; + +return static function (ContainerConfigurator $containerConfigurator): void { + $parameters = $containerConfigurator->parameters(); + + $parameters->set('sonata.admin.twig.extension.x_editable_type_mapping', [ + 'choice' => 'select', + 'boolean' => 'select', + 'text' => 'text', + 'textarea' => 'textarea', + 'html' => 'textarea', + 'email' => 'email', + 'string' => 'text', + 'smallint' => 'text', + 'bigint' => 'text', + 'integer' => 'number', + 'decimal' => 'number', + 'currency' => 'number', + 'percent' => 'number', + 'url' => 'url', + 'date' => 'date', + ]); + + $services = $containerConfigurator->services(); + + $services->set('sonata.admin.twig.extension', SonataAdminExtension::class) + ->public() + ->tag('twig.extension') + ->args([ + ref('sonata.admin.pool'), + ref('logger')->nullOnInvalid(), + ref('translator'), + ref('service_container'), + ref('security.authorization_checker'), + ]) + ->call('setXEditableTypeMapping', ['%sonata.admin.twig.extension.x_editable_type_mapping%']); + + $services->set('sonata.templates.twig.extension', TemplateRegistryExtension::class) + ->tag('twig.extension') + ->args([ + ref('sonata.admin.global_template_registry'), + ref('service_container'), + ]); +}; diff --git a/src/Resources/config/twig_string.php b/src/Resources/config/twig_string.php new file mode 100644 index 00000000000..1177e52cab0 --- /dev/null +++ b/src/Resources/config/twig_string.php @@ -0,0 +1,28 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Sonata\AdminBundle\Twig\Extension\DeprecatedTextExtension; +use Sonata\AdminBundle\Twig\Extension\StringExtension; +use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; + +return static function (ContainerConfigurator $containerConfigurator): void { + $services = $containerConfigurator->services(); + + $services->set('sonata.string.twig.extension', StringExtension::class) + ->tag('twig.extension') + ->args([null]); + + $services->set('sonata.deprecated_text.twig.extension', DeprecatedTextExtension::class) + ->tag('twig.extension') + ->deprecate('The "%service_id%" service is deprecated. You should stop using it, as it will be removed in the future.'); +}; diff --git a/src/Resources/config/validator.php b/src/Resources/config/validator.php new file mode 100644 index 00000000000..d3967a213d9 --- /dev/null +++ b/src/Resources/config/validator.php @@ -0,0 +1,28 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Sonata\Form\Validator\InlineValidator; +use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; +use function Symfony\Component\DependencyInjection\Loader\Configurator\ref; + +return static function (ContainerConfigurator $containerConfigurator): void { + $services = $containerConfigurator->services(); + + $services->set('sonata.admin.validator.inline', InlineValidator::class) + ->public() + ->tag('validator.constraint_validator', ['alias' => 'sonata.admin.validator.inline']) + ->args([ + ref('service_container'), + ref('validator.validator_factory'), + ]); +};