Skip to content

Commit

Permalink
Add level in buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
maximehuran committed Sep 6, 2024
1 parent ebb67aa commit 53b197d
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 5 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 <[email protected]>
*
* 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,
],
]);
}
}
2 changes: 2 additions & 0 deletions src/Form/Type/UiElement/ButtonLinkType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 53b197d

Please sign in to comment.