|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * @copyright Copyright (C) eZ Systems AS. All rights reserved. |
| 5 | + * @license For full copyright and license information view LICENSE file distributed with this source code. |
| 6 | + */ |
| 7 | +declare(strict_types=1); |
| 8 | + |
| 9 | +namespace EzSystems\EzPlatformUserBundle\DependencyInjection\Configuration\Parser; |
| 10 | + |
| 11 | +use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\AbstractParser; |
| 12 | +use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\SiteAccessAware\ContextualizerInterface; |
| 13 | +use Symfony\Component\Config\Definition\Builder\NodeBuilder; |
| 14 | + |
| 15 | +/** |
| 16 | + * Configuration parser for pagination limits declaration. |
| 17 | + * |
| 18 | + * Example configuration: |
| 19 | + * ```yaml |
| 20 | + * ezpublish: |
| 21 | + * system: |
| 22 | + * default: # configuration per siteaccess or siteaccess group |
| 23 | + * pagination: |
| 24 | + * user_settings_limit: 10 |
| 25 | + * ``` |
| 26 | + */ |
| 27 | +class Pagination extends AbstractParser |
| 28 | +{ |
| 29 | + /** |
| 30 | + * Adds semantic configuration definition. |
| 31 | + * |
| 32 | + * @param \Symfony\Component\Config\Definition\Builder\NodeBuilder $nodeBuilder Node just under ezpublish.system.<siteaccess> |
| 33 | + */ |
| 34 | + public function addSemanticConfig(NodeBuilder $nodeBuilder) |
| 35 | + { |
| 36 | + $nodeBuilder |
| 37 | + ->arrayNode('pagination') |
| 38 | + ->info('System pagination configuration') |
| 39 | + ->children() |
| 40 | + ->scalarNode('user_settings_limit')->isRequired()->end() |
| 41 | + ->end() |
| 42 | + ->end(); |
| 43 | + } |
| 44 | + |
| 45 | + /** |
| 46 | + * {@inheritdoc} |
| 47 | + */ |
| 48 | + public function mapConfig(array &$scopeSettings, $currentScope, ContextualizerInterface $contextualizer): void |
| 49 | + { |
| 50 | + if (empty($scopeSettings['pagination'])) { |
| 51 | + return; |
| 52 | + } |
| 53 | + |
| 54 | + $settings = $scopeSettings['pagination']; |
| 55 | + $keys = [ |
| 56 | + 'user_settings_limit', |
| 57 | + ]; |
| 58 | + |
| 59 | + foreach ($keys as $key) { |
| 60 | + if (!isset($settings[$key]) || empty($settings[$key])) { |
| 61 | + continue; |
| 62 | + } |
| 63 | + |
| 64 | + $contextualizer->setContextualParameter( |
| 65 | + sprintf('pagination.%s', $key), |
| 66 | + $currentScope, |
| 67 | + $settings[$key] |
| 68 | + ); |
| 69 | + } |
| 70 | + } |
| 71 | +} |
0 commit comments