Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Header UI element #7

Merged
merged 1 commit into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/Form/Type/MinimalWysiwygType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

/*
* This file is part of Monsieur Biz's SyliusUiElementsPlugin for Sylius.
* (c) Monsieur Biz <[email protected]>
* 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;
}
}
48 changes: 48 additions & 0 deletions src/Form/Type/UiElement/HeaderUiElementType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

/*
* This file is part of Monsieur Biz's SyliusUiElementsPlugin for Sylius.
* (c) Monsieur Biz <[email protected]>
* 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,
]);
}
}
3 changes: 3 additions & 0 deletions src/Resources/translations/messages.en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
3 changes: 3 additions & 0 deletions src/Resources/translations/messages.fr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
13 changes: 13 additions & 0 deletions src/Resources/views/Admin/UiElement/header_ui_element.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{#
UI Element template
type: header_ui_element
element fields:
- title
- description
#}
{% if element.title|default('') is not empty %}
<h1 >{{ element.title|raw }}</h1>
{% endif %}
{% if element.description|default('') is not empty %}
{{ element.description|raw }}
{% endif %}
13 changes: 13 additions & 0 deletions src/Resources/views/Shop/UiElement/header_ui_element.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{#
UI Element template
type: header_ui_element
element fields:
- title
- description
#}
{% if element.title|default('') is not empty %}
<h1 >{{ element.title|raw }}</h1>
{% endif %}
{% if element.description|default('') is not empty %}
{{ element.description|raw }}
{% endif %}
3 changes: 3 additions & 0 deletions src/Resources/views/Wireframe/header.svg.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<svg width="230" height="100" viewBox="0 0 230 100" fill="none" xmlns="http://www.w3.org/2000/svg">
<rect width="230" height="100" rx="5" fill="#7A8CCE" fill-opacity="0.1"></rect>
</svg>
Loading