From 53b197d88289cab6b00d29e3fae92307047eaa4d Mon Sep 17 00:00:00 2001 From: Maxime Huran Date: Fri, 6 Sep 2024 11:16:13 +0200 Subject: [PATCH 1/2] Add level in buttons --- src/Form/Type/LevelType.php | 40 +++++++++++++++++++ src/Form/Type/UiElement/ButtonLinkType.php | 2 + src/Resources/translations/messages.en.yml | 6 +++ src/Resources/translations/messages.fr.yml | 6 +++ .../views/Admin/UiElement/button.html.twig | 7 ++-- .../views/Shop/UiElement/button.html.twig | 4 +- 6 files changed, 60 insertions(+), 5 deletions(-) create mode 100644 src/Form/Type/LevelType.php diff --git a/src/Form/Type/LevelType.php b/src/Form/Type/LevelType.php new file mode 100644 index 00000000..33ac5b39 --- /dev/null +++ b/src/Form/Type/LevelType.php @@ -0,0 +1,40 @@ + + * + * For the full copyright and license information, please view the LICENSE.txt + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace MonsieurBiz\SyliusRichEditorPlugin\Form\Type; + +use Symfony\Component\Form\Extension\Core\Type\ChoiceType; +use Symfony\Component\OptionsResolver\OptionsResolver; + +class LevelType extends ChoiceType +{ + public const PRIMARY_LEVEL = 'primary'; + + public const SECONDARY_LEVEL = 'secondary'; + + public const TERTIARY_LEVEL = 'tertiary'; + + public function configureOptions(OptionsResolver $resolver): void + { + parent::configureOptions($resolver); + $resolver->setDefaults([ + 'label' => 'monsieurbiz_richeditor_plugin.form.level.label', + 'choices' => [ + 'monsieurbiz_richeditor_plugin.form.level.default' => '', + 'monsieurbiz_richeditor_plugin.form.level.primary' => self::PRIMARY_LEVEL, + 'monsieurbiz_richeditor_plugin.form.level.secondary' => self::SECONDARY_LEVEL, + 'monsieurbiz_richeditor_plugin.form.level.tertiary' => self::TERTIARY_LEVEL, + ], + ]); + } +} diff --git a/src/Form/Type/UiElement/ButtonLinkType.php b/src/Form/Type/UiElement/ButtonLinkType.php index ceb945ef..4b1146ee 100644 --- a/src/Form/Type/UiElement/ButtonLinkType.php +++ b/src/Form/Type/UiElement/ButtonLinkType.php @@ -14,6 +14,7 @@ namespace MonsieurBiz\SyliusRichEditorPlugin\Form\Type\UiElement; use MonsieurBiz\SyliusRichEditorPlugin\Form\Type\AlignmentType; +use MonsieurBiz\SyliusRichEditorPlugin\Form\Type\LevelType; use MonsieurBiz\SyliusRichEditorPlugin\Form\Type\LinkTypeType; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\TextType as FormTextType; @@ -78,6 +79,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'constraints' => $constraintsLinkType, ]) ->add('align', AlignmentType::class) + ->add('level', LevelType::class) ; } } diff --git a/src/Resources/translations/messages.en.yml b/src/Resources/translations/messages.en.yml index 6ffacba3..a71e472a 100644 --- a/src/Resources/translations/messages.en.yml +++ b/src/Resources/translations/messages.en.yml @@ -129,6 +129,12 @@ monsieurbiz_richeditor_plugin: center: 'Center' right: 'Right' justify: 'Justify' + level: + label: 'Level' + default: 'Default' + primary: 'Primary' + secondary: 'Secondary' + tertiary: 'Tertiary' clipboard: 'Clipboard' paste_from_clipboard: 'Paste from clipboard' paste_all_from_clipboard: 'Paste all elements' diff --git a/src/Resources/translations/messages.fr.yml b/src/Resources/translations/messages.fr.yml index 5d4df952..d8531027 100644 --- a/src/Resources/translations/messages.fr.yml +++ b/src/Resources/translations/messages.fr.yml @@ -129,6 +129,12 @@ monsieurbiz_richeditor_plugin: center: 'Centré' right: 'Droite' justify: 'Justifié' + level: + label: 'Niveau' + default: 'Aucun' + primary: 'Primaire' + secondary: 'Secondaire' + tertiary: 'Tertiaire' clipboard: 'Presse-papier' paste_from_clipboard: 'Coller depuis le presse-papier' paste_all_from_clipboard: 'Coller tous les éléments' diff --git a/src/Resources/views/Admin/UiElement/button.html.twig b/src/Resources/views/Admin/UiElement/button.html.twig index 5f7057da..256e104b 100644 --- a/src/Resources/views/Admin/UiElement/button.html.twig +++ b/src/Resources/views/Admin/UiElement/button.html.twig @@ -6,12 +6,11 @@ link link_type align + level #} {% set align = element.align is defined and element.align is not empty ? element.align : 'center' %} +{% set level = element.level is defined and element.level is not empty ? element.level : 'primary' %} {% set linkIsBlank = element.link_type is defined and element.link_type == constant('MonsieurBiz\\SyliusRichEditorPlugin\\Form\\Type\\LinkTypeType::TYPE_EXTERNAL') %} -

- - {{ element.label }} - + {{ element.label }}

diff --git a/src/Resources/views/Shop/UiElement/button.html.twig b/src/Resources/views/Shop/UiElement/button.html.twig index 8a29cba7..256e104b 100644 --- a/src/Resources/views/Shop/UiElement/button.html.twig +++ b/src/Resources/views/Shop/UiElement/button.html.twig @@ -6,9 +6,11 @@ link link_type align + level #} {% set align = element.align is defined and element.align is not empty ? element.align : 'center' %} +{% set level = element.level is defined and element.level is not empty ? element.level : 'primary' %} {% set linkIsBlank = element.link_type is defined and element.link_type == constant('MonsieurBiz\\SyliusRichEditorPlugin\\Form\\Type\\LinkTypeType::TYPE_EXTERNAL') %}

- {{ element.label }} + {{ element.label }}

From 758ed17ca189c064fb0fe11c6b9c7ae51b0b6664 Mon Sep 17 00:00:00 2001 From: Maxime Huran Date: Fri, 6 Sep 2024 11:16:42 +0200 Subject: [PATCH 2/2] Link is TextType because UrlType add `https` --- src/Form/Type/UiElement/ButtonLinkType.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Form/Type/UiElement/ButtonLinkType.php b/src/Form/Type/UiElement/ButtonLinkType.php index 4b1146ee..47a474e9 100644 --- a/src/Form/Type/UiElement/ButtonLinkType.php +++ b/src/Form/Type/UiElement/ButtonLinkType.php @@ -17,8 +17,8 @@ use MonsieurBiz\SyliusRichEditorPlugin\Form\Type\LevelType; use MonsieurBiz\SyliusRichEditorPlugin\Form\Type\LinkTypeType; use Symfony\Component\Form\AbstractType; +use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\Extension\Core\Type\TextType as FormTextType; -use Symfony\Component\Form\Extension\Core\Type\UrlType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Validator\Constraints as Assert; @@ -43,7 +43,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'message' => 'monsieurbiz_richeditor_plugin.not_valid_url', 'constraints' => [ new Assert\Url(['protocols' => ['http', 'https'], 'relativeProtocol' => true]), - new Assert\Regex(['pattern' => '`^(#|/.*)$`']), + new Assert\Regex(['pattern' => '`^(#|/|tel:|mailto:)`']), ], ]), new Assert\NotBlank([]), @@ -57,7 +57,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'message' => 'monsieurbiz_richeditor_plugin.not_valid_url', 'constraints' => [ new Assert\Url(['protocols' => ['http', 'https'], 'relativeProtocol' => true]), - new Assert\Regex(['pattern' => '`^(#|/.*)$`']), + new Assert\Regex(['pattern' => '`^(#|/|tel:|mailto:)`']), ], ]), ]; @@ -69,7 +69,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'label' => 'monsieurbiz_richeditor_plugin.ui_element.monsieurbiz.button.field.label', 'constraints' => $constraintsLabel, ]) - ->add('link', UrlType::class, [ + ->add('link', TextType::class, [ 'required' => $required, 'label' => 'monsieurbiz_richeditor_plugin.ui_element.monsieurbiz.button.field.link', 'constraints' => $constraintsLink,