vendor/easycorp/easyadmin-bundle/src/DependencyInjection/Configuration.php line 262

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the EasyAdminBundle.
  4.  *
  5.  * (c) Javier Eguiluz <javier.eguiluz@gmail.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace EasyCorp\Bundle\EasyAdminBundle\DependencyInjection;
  11. use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
  12. use Symfony\Component\Config\Definition\Builder\TreeBuilder;
  13. use Symfony\Component\Config\Definition\ConfigurationInterface;
  14. /**
  15.  * Defines the configuration options of the bundle and validates its values.
  16.  *
  17.  * @author Javier Eguiluz <javier.eguiluz@gmail.com>
  18.  */
  19. class Configuration implements ConfigurationInterface
  20. {
  21.     public function getConfigTreeBuilder()
  22.     {
  23.         $treeBuilder = new TreeBuilder('easy_admin');
  24.         $rootNode $this->getRootNode($treeBuilder'easy_admin');
  25.         $this->addDeprecationsSection($rootNode);
  26.         $this->addGlobalOptionsSection($rootNode);
  27.         $this->addDesignSection($rootNode);
  28.         $this->addViewsSection($rootNode);
  29.         $this->addEntitiesSection($rootNode);
  30.         return $treeBuilder;
  31.     }
  32.     private function addDeprecationsSection(ArrayNodeDefinition $rootNode)
  33.     {
  34.         $rootNode
  35.             // 'list_max_results' global option was deprecated in 1.0.8
  36.             // and replaced by 'list -> max_results'
  37.             ->beforeNormalization()
  38.                 ->ifTrue(function ($v) {
  39.                     return isset($v['list_max_results']);
  40.                 })
  41.                 ->then(function ($v) {
  42.                     if (!isset($v['list'])) {
  43.                         $v['list'] = array();
  44.                     }
  45.                     // if the new option is defined, don't override it with the legacy option
  46.                     if (!isset($v['list']['max_results'])) {
  47.                         $v['list']['max_results'] = $v['list_max_results'];
  48.                     }
  49.                     unset($v['list_max_results']);
  50.                     return $v;
  51.                 })
  52.             ->end()
  53.             // 'list_actions' global option was deprecated in 1.0.8
  54.             // and replaced by 'list -> actions'
  55.             ->beforeNormalization()
  56.                 ->ifTrue(function ($v) {
  57.                     return isset($v['list_actions']);
  58.                 })
  59.                 ->then(function ($v) {
  60.                     // if the new option is defined, don't override it with the legacy option
  61.                     if (!isset($v['list']['actions'])) {
  62.                         $v['list']['actions'] = $v['list_actions'];
  63.                     }
  64.                     unset($v['list_actions']);
  65.                     return $v;
  66.                 })
  67.             ->end()
  68.             // make sure the new 'design' global option exists to simplify
  69.             // updating the deprecated 'assets -> css' and 'assets -> js' options
  70.             ->beforeNormalization()
  71.                 ->always()
  72.                 ->then(function ($v) {
  73.                     if (!isset($v['design'])) {
  74.                         $v['design'] = array('assets' => array());
  75.                     }
  76.                     return $v;
  77.                 })
  78.             ->end()
  79.             // 'assets -> css' global option was deprecated in 1.1.0
  80.             // and replaced by 'design -> assets -> css'
  81.             ->beforeNormalization()
  82.                 ->ifTrue(function ($v) {
  83.                     return isset($v['assets']['css']);
  84.                 })
  85.                 ->then(function ($v) {
  86.                     // if the new option is defined, don't override it with the legacy option
  87.                     if (!isset($v['design']['assets']['css'])) {
  88.                         $v['design']['assets']['css'] = $v['assets']['css'];
  89.                     }
  90.                     unset($v['assets']['css']);
  91.                     return $v;
  92.                 })
  93.             ->end()
  94.             // 'assets -> js' global option was deprecated in 1.1.0
  95.             // and replaced by 'design -> assets -> js'
  96.             ->beforeNormalization()
  97.                 ->ifTrue(function ($v) {
  98.                     return isset($v['assets']['js']);
  99.                 })
  100.                 ->then(function ($v) {
  101.                     // if the new option is defined, don't override it with the legacy option
  102.                     if (!isset($v['design']['assets']['js'])) {
  103.                         $v['design']['assets']['js'] = $v['assets']['js'];
  104.                     }
  105.                     unset($v['assets']['js']);
  106.                     return $v;
  107.                 })
  108.             ->end()
  109.             // after updating 'assets -> css' and 'assets -> js' deprecated options,
  110.             // remove the parent 'assets' deprecated option if it's defined
  111.             ->beforeNormalization()
  112.                 ->always()
  113.                 ->then(function ($v) {
  114.                     if (isset($v['assets'])) {
  115.                         unset($v['assets']);
  116.                     }
  117.                     return $v;
  118.                 })
  119.             ->end()
  120.             ->children()
  121.                 ->variableNode('list_actions')
  122.                     ->info('DEPRECATED: use the "actions" option of the "list" view.')
  123.                 ->end()
  124.                 ->integerNode('list_max_results')
  125.                     ->info('DEPRECATED: use "max_results" option under the "list" global key.')
  126.                 ->end()
  127.                 ->arrayNode('assets')
  128.                     ->children()
  129.                         ->arrayNode('css')
  130.                             ->info('DEPRECATED: use the "design -> assets -> css" option.')
  131.                         ->end()
  132.                         ->arrayNode('js')
  133.                             ->info('DEPRECATED: use the "design -> assets -> js" option.')
  134.                         ->end()
  135.                     ->end()
  136.                 ->end()
  137.             ->end()
  138.         ;
  139.     }
  140.     private function addGlobalOptionsSection(ArrayNodeDefinition $rootNode)
  141.     {
  142.         $rootNode
  143.             ->children()
  144.                 ->scalarNode('site_name')
  145.                     ->defaultValue('EasyAdmin')
  146.                     ->info('The name displayed as the title of the administration zone (e.g. company name, project name).')
  147.                 ->end()
  148.                 ->arrayNode('formats')
  149.                     ->addDefaultsIfNotSet()
  150.                     ->children()
  151.                         ->scalarNode('date')
  152.                             ->defaultValue('Y-m-d')
  153.                             ->info('The PHP date format applied to "date" and "date_immutable" field types.')
  154.                             ->example('d/m/Y (see http://php.net/manual/en/function.date.php)')
  155.                         ->end()
  156.                         ->scalarNode('time')
  157.                             ->defaultValue('H:i:s')
  158.                             ->info('The PHP time format applied to "time" and "time_immutable" field types.')
  159.                             ->example('h:i a (see http://php.net/date)')
  160.                         ->end()
  161.                         ->scalarNode('datetime')
  162.                             ->defaultValue('F j, Y H:i')
  163.                             ->info('The PHP date/time format applied to "datetime" and "datetime_immutable" field types.')
  164.                             ->example('l, F jS Y / h:i (see http://php.net/date)')
  165.                         ->end()
  166.                         ->scalarNode('number')
  167.                             ->info('The sprintf-compatible format applied to numeric values.')
  168.                             ->example('%.2d (see http://php.net/sprintf)')
  169.                         ->end()
  170.                         ->scalarNode('dateinterval')
  171.                             ->defaultValue('%%y Year(s) %%m Month(s) %%d Day(s)')
  172.                             ->info('The PHP dateinterval-compatible format applied to "dateinterval" field types.')
  173.                             ->example('%%y Year(s) %%m Month(s) %%d Day(s) (see http://php.net/manual/en/dateinterval.format.php)')
  174.                         ->end()
  175.                     ->end()
  176.                 ->end()
  177.                 ->variableNode('disabled_actions')
  178.                     ->info('The names of the actions disabled for all backend entities.')
  179.                     ->defaultValue(array())
  180.                     ->validate()
  181.                         ->ifTrue(function ($v) {
  182.                             return false === is_array($v);
  183.                         })
  184.                         ->thenInvalid('The disabled_actions option must be an array of action names.')
  185.                     ->end()
  186.                 ->end()
  187.                 ->scalarNode('translation_domain')
  188.                     ->validate()
  189.                         ->ifTrue(function ($v) {
  190.                             return '' === $v;
  191.                         })
  192.                         ->thenInvalid('The translation_domain option cannot be an empty string (use false to disable translations).')
  193.                     ->end()
  194.                     ->defaultValue('messages')
  195.                     ->info('The translation domain used to translate the labels, titles and help messages of all entities.')
  196.                 ->end()
  197.             ->end()
  198.         ;
  199.     }
  200.     private function addDesignSection(ArrayNodeDefinition $rootNode)
  201.     {
  202.         $rootNode
  203.             ->children()
  204.                 ->arrayNode('design')
  205.                     ->addDefaultsIfNotSet()
  206.                     ->children()
  207.                         // the 'theme' option is not used at the moment, but it allows us to be prepared for the future
  208.                         ->scalarNode('theme')
  209.                             ->defaultValue('default')
  210.                             ->info('The theme used to render the backend pages. For now this value can only be "default".')
  211.                             ->beforeNormalization()
  212.                                 ->always(function ($v) {
  213.                                     @trigger_error('The "design.theme" option is deprecated since EasyAdmin 1.x version and it will be removed in 2.0.'E_USER_DEPRECATED);
  214.                                     return $v;
  215.                                 })
  216.                             ->end()
  217.                             ->validate()
  218.                                 ->ifNotInArray(array('default'))
  219.                                 ->thenInvalid('The theme name can only be "default".')
  220.                             ->end()
  221.                         ->end()
  222.                         ->enumNode('color_scheme')
  223.                             ->values(array('dark''light'))
  224.                             ->info('The color scheme applied to the backend design (values: "dark" or "light").')
  225.                             ->defaultValue('dark')
  226.                             ->treatNullLike('dark')
  227.                             ->beforeNormalization()
  228.                                 ->always(function ($v) {
  229.                                     @trigger_error('The "design.color_scheme" option is deprecated since EasyAdmin 1.x version and it will be removed in 2.0.'E_USER_DEPRECATED);
  230.                                     return $v;
  231.                                 })
  232.                             ->end()
  233.                         ->end()
  234.                         ->booleanNode('rtl')
  235.                             ->info('If true, the interface uses RTL (right-to-left) writing (needed for Arabic, Hebrew and Persian).')
  236.                         ->end()
  237.                         ->scalarNode('brand_color')
  238.                             ->info('The color used in the backend design to highlight important elements.')
  239.                             ->defaultValue('#205081')
  240.                             ->treatNullLike('#205081')
  241.                             ->validate()
  242.                                 // if present, remove the trailing ';' to avoid CSS issues
  243.                                 ->ifTrue(function ($v) {
  244.                                     return ';' === substr(trim($v), -1);
  245.                                 })
  246.                                 ->then(function ($v) {
  247.                                     return trim(substr(trim($v), 0, -1));
  248.                                 })
  249.                             ->end()
  250.                         ->end()
  251.                         ->variableNode('form_theme')
  252.                             ->defaultValue(array('@EasyAdmin/form/bootstrap_3_horizontal_layout.html.twig'))
  253.                             ->treatNullLike(array('@EasyAdmin/form/bootstrap_3_horizontal_layout.html.twig'))
  254.                             ->info('The form theme applied to backend forms. Allowed values: "horizontal", "vertical", any valid form theme path or an array of theme paths.')
  255.                             ->beforeNormalization()
  256.                                 ->ifTrue(function ($v) {
  257.                                     return in_array($v, array('@EasyAdmin/form/bootstrap_3_horizontal_layout.html.twig''@EasyAdmin/form/bootstrap_3_layout.html.twig'), true);
  258.                                 })
  259.                                 ->then(function ($v) {
  260.                                     @trigger_error(sprintf('The "%s" form theme is deprecated since EasyAdmin 1.x version and it will be removed in 2.0. Remove "%s" from the "design.form_theme" config option.'$v$v), E_USER_DEPRECATED);
  261.                                     return $v;
  262.                                 })
  263.                             ->end()
  264.                             ->validate()
  265.                                 ->ifString()->then(function ($v) {
  266.                                     return array($v);
  267.                                 })
  268.                             ->end()
  269.                             ->validate()
  270.                                 ->ifArray()->then(function ($values) {
  271.                                     foreach ($values as $k => $v) {
  272.                                         $deprecationMessage sprintf('The "%s" form theme shortcut is deprecated since EasyAdmin 1.x version and it will be removed in 2.0. Remove "%s" from the "design.form_theme" config option.'$v$v);
  273.                                         if ('horizontal' === $v) {
  274.                                             @trigger_error($deprecationMessageE_USER_DEPRECATED);
  275.                                             $values[$k] = '@EasyAdmin/form/bootstrap_3_horizontal_layout.html.twig';
  276.                                         } elseif ('vertical' === $v) {
  277.                                             @trigger_error($deprecationMessageE_USER_DEPRECATED);
  278.                                             $values[$k] = '@EasyAdmin/form/bootstrap_3_layout.html.twig';
  279.                                         }
  280.                                     }
  281.                                     return $values;
  282.                                 })
  283.                             ->end()
  284.                         ->end()
  285.                         ->arrayNode('assets')
  286.                             ->addDefaultsIfNotSet()
  287.                             ->children()
  288.                                 ->arrayNode('css')
  289.                                     ->prototype('scalar')->end()
  290.                                     ->info('The array of CSS assets to load in all backend pages.')
  291.                                 ->end()
  292.                                 ->arrayNode('js')
  293.                                     ->prototype('scalar')->end()
  294.                                     ->info('The array of JavaScript assets to load in all backend pages.')
  295.                                 ->end()
  296.                                 ->arrayNode('favicon')
  297.                                     ->addDefaultsIfNotSet()
  298.                                     ->info('The favicon to use in all backend pages.')
  299.                                     ->children()
  300.                                         ->scalarNode('path')->cannotBeEmpty()->defaultValue('favicon.ico')->end()
  301.                                         ->scalarNode('mime_type')->defaultValue('image/x-icon')->end()
  302.                                     ->end()
  303.                                     ->beforeNormalization()
  304.                                         ->always(function ($v) {
  305.                                             if (is_string($v)) {
  306.                                                 $v = array('path' => $v);
  307.                                             }
  308.                                             $mimeTypes = array(
  309.                                                 'ico' => 'image/x-icon',
  310.                                                 'png' => 'image/png',
  311.                                                 'gif' => 'image/gif',
  312.                                                 'jpg' => 'image/jpeg',
  313.                                                 'jpeg' => 'image/jpeg',
  314.                                             );
  315.                                             if (!isset($v['mime_type']) && isset($mimeTypes[$ext pathinfo($v['path'], PATHINFO_EXTENSION)])) {
  316.                                                 $v['mime_type'] = $mimeTypes[$ext];
  317.                                             } elseif (!isset($v['mime_type'])) {
  318.                                                 $v['mime_type'] = null;
  319.                                             }
  320.                                             return $v;
  321.                                         })
  322.                                     ->end()
  323.                                     ->validate()
  324.                                         ->ifTrue(function ($v) {
  325.                                             return empty($v['mime_type']);
  326.                                         })
  327.                                         ->thenInvalid('The "mime_type" key is required as we were unable to guess it from the favicon extension.')
  328.                                     ->end()
  329.                                 ->end()
  330.                             ->end()
  331.                         ->end()
  332.                         ->arrayNode('templates')
  333.                             ->info('The custom templates used to render each backend element.')
  334.                             ->children()
  335.                                 ->scalarNode('layout')->info('Used to decorate the main templates (list, edit, new and show)')->end()
  336.                                 ->scalarNode('menu')->info('Used to render the main menu')->end()
  337.                                 ->scalarNode('edit')->info('Used to render the page where entities are edited')->end()
  338.                                 ->scalarNode('list')->info('Used to render the listing page and the search results page')->end()
  339.                                 ->scalarNode('new')->info('Used to render the page where new entities are created')->end()
  340.                                 ->scalarNode('show')->info('Used to render the contents stored by a given entity')->end()
  341.                                 ->scalarNode('exception')->info('Used to render the error page when some exception happens')->end()
  342.                                 ->scalarNode('flash_messages')->info('Used to render the notification area were flash messages are displayed')->end()
  343.                                 ->scalarNode('paginator')->info('Used to render the paginator in the list page')->end()
  344.                                 ->scalarNode('field_array')->info('Used to render array field types')->end()
  345.                                 ->scalarNode('field_association')->info('Used to render fields that store Doctrine associations')->end()
  346.                                 ->scalarNode('field_bigint')->info('Used to render bigint field types')->end()
  347.                                 ->scalarNode('field_boolean')->info('Used to render boolean field types')->end()
  348.                                 ->scalarNode('field_date')->info('Used to render date and date_immutable field types')->end()
  349.                                 ->scalarNode('field_datetime')->info('Used to render datetime and datetime_immutable field types')->end()
  350.                                 ->scalarNode('field_datetimetz')->info('Used to render datetimetz field types')->end()
  351.                                 ->scalarNode('field_decimal')->info('Used to render decimal field types')->end()
  352.                                 ->scalarNode('field_email')->info('Used to render clickable email addresses')->end()
  353.                                 ->scalarNode('field_float')->info('Used to render float field types')->end()
  354.                                 ->scalarNode('field_id')->info('Used to render the field called "id". This avoids formatting its value as any other regular number (with decimals and thousand separators) ')->end()
  355.                                 ->scalarNode('field_image')->info('Used to render image field types (a special type that displays the image contents)')->end()
  356.                                 ->scalarNode('field_integer')->info('Used to render integer field types')->end()
  357.                                 ->scalarNode('field_raw')->info('Used to render unescaped values')->end()
  358.                                 ->scalarNode('field_simple_array')->info('Used to render simple array field types')->end()
  359.                                 ->scalarNode('field_smallint')->info('Used to render smallint field types')->end()
  360.                                 ->scalarNode('field_string')->info('Used to render string field types')->end()
  361.                                 ->scalarNode('field_tel')->info('Used to render clickable telephone number')->end()
  362.                                 ->scalarNode('field_text')->info('Used to render text field types')->end()
  363.                                 ->scalarNode('field_time')->info('Used to render time and time_immutable field types')->end()
  364.                                 ->scalarNode('field_toggle')->info('Used to render toggle field types (a special type that display booleans as flip switches)')->end()
  365.                                 ->scalarNode('field_url')->info('Used to render clickable URLs')->end()
  366.                                 ->scalarNode('label_empty')->info('Used when the field to render is an empty collection')->end()
  367.                                 ->scalarNode('label_inaccessible')->info('Used when is not possible to access the value of the field to render (there is no getter or public property)')->end()
  368.                                 ->scalarNode('label_null')->info('Used when the value of the field to render is null')->end()
  369.                                 ->scalarNode('label_undefined')->info('Used when any kind of error or exception happens when trying to access the value of the field to render')->end()
  370.                             ->end()
  371.                         ->end()
  372.                         ->arrayNode('menu')
  373.                             ->normalizeKeys(false)
  374.                             ->defaultValue(array())
  375.                             ->info('The items to display in the main menu.')
  376.                             ->prototype('variable')
  377.                         ->end()
  378.                     ->end()
  379.                 ->end()
  380.             ->end()
  381.         ;
  382.     }
  383.     private function addViewsSection(ArrayNodeDefinition $rootNode)
  384.     {
  385.         $rootNode
  386.             ->children()
  387.                 ->arrayNode('list')
  388.                     ->addDefaultsIfNotSet()
  389.                     ->children()
  390.                         ->scalarNode('title')
  391.                             ->info('The visible page title displayed in the list view.')
  392.                         ->end()
  393.                         ->arrayNode('actions')
  394.                             ->prototype('variable')->end()
  395.                             ->info('The list of actions enabled in the "list" view.')
  396.                         ->end()
  397.                         ->integerNode('max_results')
  398.                             ->defaultValue(15)
  399.                             ->info('The maximum number of items to show on listing and search pages.')
  400.                         ->end()
  401.                     ->end()
  402.                 ->end()
  403.                 ->arrayNode('search')
  404.                     ->addDefaultsIfNotSet()
  405.                     ->children()
  406.                         ->scalarNode('title')
  407.                             ->info('The visible page title displayed in the search view.')
  408.                         ->end()
  409.                     ->end()
  410.                 ->end()
  411.                 ->arrayNode('edit')
  412.                     ->addDefaultsIfNotSet()
  413.                     ->children()
  414.                         ->scalarNode('title')
  415.                             ->info('The visible page title displayed in the edit view.')
  416.                         ->end()
  417.                         ->arrayNode('actions')
  418.                             ->prototype('variable')->end()
  419.                             ->info('The list of actions enabled in the "edit" view.')
  420.                         ->end()
  421.                     ->end()
  422.                 ->end()
  423.                 ->arrayNode('new')
  424.                     ->addDefaultsIfNotSet()
  425.                     ->children()
  426.                         ->scalarNode('title')
  427.                             ->info('The visible page title displayed in the new view.')
  428.                         ->end()
  429.                         ->arrayNode('actions')
  430.                             ->prototype('variable')->end()
  431.                             ->info('The list of actions enabled in the "new" view.')
  432.                         ->end()
  433.                     ->end()
  434.                 ->end()
  435.                 ->arrayNode('show')
  436.                     ->addDefaultsIfNotSet()
  437.                     ->children()
  438.                         ->scalarNode('title')
  439.                             ->info('The visible page title displayed in the show view.')
  440.                         ->end()
  441.                         ->arrayNode('actions')
  442.                             ->prototype('variable')->end()
  443.                             ->info('The list of actions enabled in the "show" view.')
  444.                         ->end()
  445.                         ->integerNode('max_results')
  446.                             ->defaultValue(10)
  447.                             ->info('The maximum number of items displayed for related fields in the show page and for autocomplete fields in the new/edit pages.')
  448.                         ->end()
  449.                     ->end()
  450.                 ->end()
  451.             ->end()
  452.         ;
  453.     }
  454.     private function addEntitiesSection(ArrayNodeDefinition $rootNode)
  455.     {
  456.         $rootNode
  457.             ->children()
  458.                 ->arrayNode('entities')
  459.                     ->normalizeKeys(false)
  460.                     ->useAttributeAsKey('name'false)
  461.                     ->defaultValue(array())
  462.                     ->info('The list of entities to manage in the administration zone.')
  463.                     ->prototype('variable')
  464.                 ->end()
  465.             ->end()
  466.         ;
  467.     }
  468.     private function getRootNode(TreeBuilder $treeBuilder$name)
  469.     {
  470.         // BC layer for symfony/config 4.1 and older
  471.         if (!method_exists($treeBuilder'getRootNode')) {
  472.             return $treeBuilder->root($name);
  473.         }
  474.         return $treeBuilder->getRootNode();
  475.     }
  476. }
  477. class_alias('EasyCorp\Bundle\EasyAdminBundle\DependencyInjection\Configuration''JavierEguiluz\Bundle\EasyAdminBundle\DependencyInjection\Configuration'false);