Skip to content

Commit

Permalink
Merge pull request #240 from maximehuran/feature/buttons-level
Browse files Browse the repository at this point in the history
Add buttons level in button element
  • Loading branch information
maximehuran authored Sep 6, 2024
2 parents ebb67aa + 758ed17 commit f5dc440
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 9 deletions.
40 changes: 40 additions & 0 deletions src/Form/Type/LevelType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

/*
* This file is part of Monsieur Biz' Rich Editor plugin for Sylius.
*
* (c) Monsieur Biz <sylius@monsieurbiz.com>
*
* 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,
],
]);
}
}
10 changes: 6 additions & 4 deletions src/Form/Type/UiElement/ButtonLinkType.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
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;
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;

Expand All @@ -42,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([]),
Expand All @@ -56,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:)`']),
],
]),
];
Expand All @@ -68,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,
Expand All @@ -78,6 +79,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
'constraints' => $constraintsLinkType,
])
->add('align', AlignmentType::class)
->add('level', LevelType::class)
;
}
}
6 changes: 6 additions & 0 deletions src/Resources/translations/messages.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
6 changes: 6 additions & 0 deletions src/Resources/translations/messages.fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
7 changes: 3 additions & 4 deletions src/Resources/views/Admin/UiElement/button.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -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') %}

<p style="text-align: {{align}};">
<a href="{{ element.link }}"{% if linkIsBlank %} target="_blank" rel="noopener noreferrer"{% endif %} class="ui primary button massive">
{{ element.label }}
</a>
<a href="{{ element.link }}"{% if linkIsBlank %} target="_blank" rel="noopener noreferrer"{% endif %} class="ui {{ level }} button massive">{{ element.label }}</a>
</p>
4 changes: 3 additions & 1 deletion src/Resources/views/Shop/UiElement/button.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -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') %}
<p style="text-align: {{align}};">
<a href="{{ element.link }}"{% if linkIsBlank %} target="_blank" rel="noopener noreferrer"{% endif %} class="ui primary button massive">{{ element.label }}</a>
<a href="{{ element.link }}"{% if linkIsBlank %} target="_blank" rel="noopener noreferrer"{% endif %} class="ui {{ level }} button massive">{{ element.label }}</a>
</p>

0 comments on commit f5dc440

Please sign in to comment.