vendor/ezsystems/ezplatform-admin-ui/src/lib/UserSetting/AutosaveInterval.php line 19

Open in your IDE?
  1. <?php
  2. /**
  3.  * @copyright Copyright (C) Ibexa 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\EzPlatformAdminUi\UserSetting;
  8. use eZ\Publish\Core\MVC\ConfigResolverInterface;
  9. use EzSystems\EzPlatformUser\UserSetting\FormMapperInterface;
  10. use EzSystems\EzPlatformUser\UserSetting\ValueDefinitionInterface;
  11. use JMS\TranslationBundle\Annotation\Desc;
  12. use Symfony\Component\Form\Extension\Core\Type\NumberType;
  13. use Symfony\Component\Form\FormBuilderInterface;
  14. use Symfony\Contracts\Translation\TranslatorInterface;
  15. class AutosaveInterval implements ValueDefinitionInterfaceFormMapperInterface
  16. {
  17.     /** @var \Symfony\Contracts\Translation\TranslatorInterface */
  18.     private $translator;
  19.     /** @var \eZ\Publish\Core\MVC\ConfigResolverInterface */
  20.     private $configResolver;
  21.     public function __construct(
  22.         TranslatorInterface $translator,
  23.         ConfigResolverInterface $configResolver
  24.     ) {
  25.         $this->translator $translator;
  26.         $this->configResolver $configResolver;
  27.     }
  28.     public function getName(): string
  29.     {
  30.         return $this->getTranslatedName();
  31.     }
  32.     public function getDescription(): string
  33.     {
  34.         return $this->getTranslatedDescription();
  35.     }
  36.     public function getDisplayValue(string $storageValue): string
  37.     {
  38.         return $storageValue;
  39.     }
  40.     public function getDefaultValue(): string
  41.     {
  42.         return (string)$this->configResolver->getParameter('autosave.interval');
  43.     }
  44.     public function mapFieldForm(
  45.         FormBuilderInterface $formBuilder,
  46.         ValueDefinitionInterface $value
  47.     ): FormBuilderInterface {
  48.         return $formBuilder->create(
  49.             'value',
  50.             NumberType::class,
  51.             [
  52.                 'attr' => ['min' => 30],
  53.                 'required' => true,
  54.                 'label' => $this->getTranslatedDescription(),
  55.             ]
  56.         );
  57.     }
  58.     private function getTranslatedName(): string
  59.     {
  60.         return $this->translator->trans(
  61.             /** @Desc("Autosave interval") */
  62.             'settings.autosave_interval.value.title',
  63.             [],
  64.             'user_settings'
  65.         );
  66.     }
  67.     private function getTranslatedDescription(): string
  68.     {
  69.         return $this->translator->trans(
  70.             /** @Desc("Seconds till next draft autosave") */
  71.             'settings.autosave_interval.value.description',
  72.             [],
  73.             'user_settings'
  74.         );
  75.     }
  76. }