vendor/ezsystems/ezplatform-user/src/lib/UserSetting/Setting/SubitemsLimit.php line 18

Open in your IDE?
  1. <?php
  2. /**
  3.  * @copyright Copyright (C) eZ Systems AS. All rights reserved.
  4.  * @license For full copyright and license information view LICENSE file distributed with this source code.
  5.  */
  6. declare(strict_types=1);
  7. namespace EzSystems\EzPlatformUser\UserSetting\Setting;
  8. use eZ\Publish\Core\MVC\ConfigResolverInterface;
  9. use EzSystems\EzPlatformUser\UserSetting\FormMapperInterface;
  10. use EzSystems\EzPlatformUser\UserSetting\ValueDefinitionInterface;
  11. use Symfony\Component\Form\Extension\Core\Type\NumberType;
  12. use Symfony\Component\Form\FormBuilderInterface;
  13. use Symfony\Contracts\Translation\TranslatorInterface;
  14. class SubitemsLimit implements ValueDefinitionInterfaceFormMapperInterface
  15. {
  16.     /** @var \Symfony\Contracts\Translation\TranslatorInterface */
  17.     private $translator;
  18.     /** @var \eZ\Publish\Core\MVC\ConfigResolverInterface */
  19.     private $configResolver;
  20.     public function __construct(TranslatorInterface $translatorConfigResolverInterface $configResolver)
  21.     {
  22.         $this->translator $translator;
  23.         $this->configResolver $configResolver;
  24.     }
  25.     /**
  26.      * {@inheritdoc}
  27.      */
  28.     public function getName(): string
  29.     {
  30.         return $this->getTranslatedName();
  31.     }
  32.     /**
  33.      * {@inheritdoc}
  34.      */
  35.     public function getDescription(): string
  36.     {
  37.         return $this->getTranslatedDescription();
  38.     }
  39.     /**
  40.      * {@inheritdoc}
  41.      */
  42.     public function getDisplayValue(string $storageValue): string
  43.     {
  44.         return $storageValue;
  45.     }
  46.     /**
  47.      * {@inheritdoc}
  48.      */
  49.     public function getDefaultValue(): string
  50.     {
  51.         return (string)$this->configResolver->getParameter('subitems_module.limit');
  52.     }
  53.     /**
  54.      * {@inheritdoc}
  55.      */
  56.     public function mapFieldForm(FormBuilderInterface $formBuilderValueDefinitionInterface $value): FormBuilderInterface
  57.     {
  58.         return $formBuilder->create(
  59.             'value',
  60.             NumberType::class,
  61.             [
  62.                 'attr' => ['min' => 1],
  63.                 'required' => true,
  64.                 'label' => $this->getTranslatedDescription(),
  65.             ]
  66.         );
  67.     }
  68.     /**
  69.      * @return string
  70.      */
  71.     private function getTranslatedName(): string
  72.     {
  73.         return $this->translator->trans(
  74.             /** @Desc("Sub-items") */
  75.             'settings.subitems_limit.value.title',
  76.             [],
  77.             'user_settings'
  78.         );
  79.     }
  80.     /**
  81.      * @return string
  82.      */
  83.     private function getTranslatedDescription(): string
  84.     {
  85.         return $this->translator->trans(
  86.             /** @Desc("Number of items displayed in the table") */
  87.             'settings.subitems_limit.value.description',
  88.             [],
  89.             'user_settings'
  90.         );
  91.     }
  92. }