From 1438c50a7139ff37dac12ef48f26f8f9b862a5b2 Mon Sep 17 00:00:00 2001 From: David Buros Date: Tue, 27 Aug 2024 15:51:39 +0200 Subject: [PATCH] feat(ui-element): Add Header Ui element --- src/Form/Type/MinimalWysiwygType.php | 32 +++++++++++++ .../Type/UiElement/HeaderUiElementType.php | 48 +++++++++++++++++++ src/Resources/translations/messages.en.yaml | 3 ++ src/Resources/translations/messages.fr.yaml | 3 ++ .../UiElement/header_ui_element.html.twig | 13 +++++ .../UiElement/header_ui_element.html.twig | 13 +++++ src/Resources/views/Wireframe/header.svg.twig | 3 ++ 7 files changed, 115 insertions(+) create mode 100644 src/Form/Type/MinimalWysiwygType.php create mode 100644 src/Form/Type/UiElement/HeaderUiElementType.php create mode 100644 src/Resources/views/Admin/UiElement/header_ui_element.html.twig create mode 100644 src/Resources/views/Shop/UiElement/header_ui_element.html.twig create mode 100644 src/Resources/views/Wireframe/header.svg.twig diff --git a/src/Form/Type/MinimalWysiwygType.php b/src/Form/Type/MinimalWysiwygType.php new file mode 100644 index 0000000..2065719 --- /dev/null +++ b/src/Form/Type/MinimalWysiwygType.php @@ -0,0 +1,32 @@ + + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace MonsieurBiz\SyliusUiElementsPlugin\Form\Type; + +use MonsieurBiz\SyliusRichEditorPlugin\Form\Type\WysiwygType; +use Symfony\Component\Form\AbstractType; +use Symfony\Component\OptionsResolver\OptionsResolver; + +final class MinimalWysiwygType extends AbstractType +{ + public function configureOptions(OptionsResolver $resolver): void + { + parent::configureOptions($resolver); + $resolver->setDefault('editor_toolbar_type', 'custom'); + $resolver->setDefault('editor_toolbar_buttons', [['bold', 'underline', 'italic', 'strike']]); + $resolver->setDefault('editor_height', 10); + } + + public function getParent(): string + { + return WysiwygType::class; + } +} diff --git a/src/Form/Type/UiElement/HeaderUiElementType.php b/src/Form/Type/UiElement/HeaderUiElementType.php new file mode 100644 index 0000000..91dcf52 --- /dev/null +++ b/src/Form/Type/UiElement/HeaderUiElementType.php @@ -0,0 +1,48 @@ + + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace MonsieurBiz\SyliusUiElementsPlugin\Form\Type\UiElement; + +use MonsieurBiz\SyliusRichEditorPlugin\Attribute\AsUiElement; +use MonsieurBiz\SyliusRichEditorPlugin\Attribute\TemplatesUiElement; +use MonsieurBiz\SyliusUiElementsPlugin\Form\Type\MinimalWysiwygType; +use Symfony\Component\Form\AbstractType; +use Symfony\Component\Form\FormBuilderInterface; + +#[AsUiElement( + code: 'monsieurbiz_ui_elements.header_ui_element', + icon: 'heading', + title: 'monsieurbiz_ui_elements.ui_element.header_ui_element.title', + description: 'monsieurbiz_ui_elements.ui_element.header_ui_element.description', + templates: new TemplatesUiElement( + adminRender: '@MonsieurBizSyliusUiElementsPlugin/Admin/UiElement/header_ui_element.html.twig', + frontRender: '@MonsieurBizSyliusUiElementsPlugin/Shop/UiElement/header_ui_element.html.twig', + ), + wireframe: 'header', + tags: [], +)] +class HeaderUiElementType extends AbstractType +{ + /** + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function buildForm(FormBuilderInterface $builder, array $options): void + { + $builder->add('title', MinimalWysiwygType::class, [ + 'label' => 'monsieurbiz_ui_elements.common.fields.title', + 'required' => false, + ]); + $builder->add('description', MinimalWysiwygType::class, [ + 'label' => 'monsieurbiz_ui_elements.common.fields.subtitle', + 'required' => false, + ]); + } +} diff --git a/src/Resources/translations/messages.en.yaml b/src/Resources/translations/messages.en.yaml index c173adb..0c6ad77 100644 --- a/src/Resources/translations/messages.en.yaml +++ b/src/Resources/translations/messages.en.yaml @@ -64,3 +64,6 @@ monsieurbiz_ui_elements: buttons: add_element: "Add logo" delete_element: "Delete logo" + header_ui_element: + title: "Header Element" + description: "Header with title and subtitle" diff --git a/src/Resources/translations/messages.fr.yaml b/src/Resources/translations/messages.fr.yaml index 4ca1189..9a99140 100644 --- a/src/Resources/translations/messages.fr.yaml +++ b/src/Resources/translations/messages.fr.yaml @@ -64,3 +64,6 @@ monsieurbiz_ui_elements: buttons: add_element: "Ajouter un logo" delete_element: "Supprimer un logo" + header_ui_element: + title: "Lame En-tĂȘte" + description: "En-tĂȘte de page avec titre et description" diff --git a/src/Resources/views/Admin/UiElement/header_ui_element.html.twig b/src/Resources/views/Admin/UiElement/header_ui_element.html.twig new file mode 100644 index 0000000..a69ba38 --- /dev/null +++ b/src/Resources/views/Admin/UiElement/header_ui_element.html.twig @@ -0,0 +1,13 @@ +{# +UI Element template +type: header_ui_element +element fields: + - title + - description +#} +{% if element.title|default('') is not empty %} +

{{ element.title|raw }}

+{% endif %} +{% if element.description|default('') is not empty %} + {{ element.description|raw }} +{% endif %} diff --git a/src/Resources/views/Shop/UiElement/header_ui_element.html.twig b/src/Resources/views/Shop/UiElement/header_ui_element.html.twig new file mode 100644 index 0000000..a69ba38 --- /dev/null +++ b/src/Resources/views/Shop/UiElement/header_ui_element.html.twig @@ -0,0 +1,13 @@ +{# +UI Element template +type: header_ui_element +element fields: + - title + - description +#} +{% if element.title|default('') is not empty %} +

{{ element.title|raw }}

+{% endif %} +{% if element.description|default('') is not empty %} + {{ element.description|raw }} +{% endif %} diff --git a/src/Resources/views/Wireframe/header.svg.twig b/src/Resources/views/Wireframe/header.svg.twig new file mode 100644 index 0000000..3abf037 --- /dev/null +++ b/src/Resources/views/Wireframe/header.svg.twig @@ -0,0 +1,3 @@ + + +