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

feat(ui-element): Add FiguresUiElement #3

Merged
merged 1 commit into from
Aug 6, 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
41 changes: 41 additions & 0 deletions src/Form/Type/FigureType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?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 Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Validator\Constraints as Assert;

class FigureType extends AbstractType
{
/**
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('figure', TextType::class, [
'required' => true,
'label' => 'monsieurbiz_ui_elements.ui_element.figures_ui_element.fields.figure',
'constraints' => [
new Assert\NotBlank(),
new Assert\Length(['max' => 255]),
],
])
->add('description', TextType::class, [
'required' => false,
'label' => 'monsieurbiz_ui_elements.common.fields.description',
])
;
}
}
52 changes: 52 additions & 0 deletions src/Form/Type/UiElement/FiguresUiElementType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?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\FigureType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Validator\Constraints as Assert;

#[AsUiElement(
code: 'monsieurbiz_ui_elements.figures_ui_element',
icon: 'percent',
title: 'monsieurbiz_ui_elements.ui_element.figures_ui_element.title',
description: 'monsieurbiz_ui_elements.ui_element.figures_ui_element.description',
templates: new TemplatesUiElement(
adminRender: '@MonsieurBizSyliusUiElementsPlugin/Admin/UiElement/figures_ui_element.html.twig',
frontRender: '@MonsieurBizSyliusUiElementsPlugin/Front/UiElement/figures_ui_element.html.twig',
),
)]
class FiguresUiElementType extends AbstractType
{
/**
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder->add('figures', CollectionType::class, [
'label' => 'monsieurbiz_ui_elements.ui_element.figures_ui_element.fields.figures',
'button_add_label' => 'monsieurbiz_ui_elements.ui_element.figures_ui_element.buttons.add_element',
'button_delete_label' => 'monsieurbiz_ui_elements.ui_element.figures_ui_element.buttons.delete_element',
'entry_type' => FigureType::class,
'allow_add' => true,
'allow_delete' => true,
'constraints' => [new Assert\Valid()],
'attr' => [
'class' => 'ui segment secondary',
],
]);
}
}
9 changes: 9 additions & 0 deletions src/Resources/translations/messages.en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,12 @@ monsieurbiz_ui_elements:
choices:
internal: "Internal"
external: "External"
figures_ui_element:
title: "Key figures"
description: "Collection of key figures"
fields:
figures: "Key figures"
figure: "Key figure"
buttons:
add_element: "Add key figure"
delete_element: "Delete key figure"
9 changes: 9 additions & 0 deletions src/Resources/translations/messages.fr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,12 @@ monsieurbiz_ui_elements:
choices:
internal: "Interne"
external: "Externe"
figures_ui_element:
title: "Chiffres clés"
description: "Ensemble de chiffres clés"
fields:
figures: "Chiffres clés"
figure: "Chiffre clé"
buttons:
add_element: "Ajouter un chiffre clé"
delete_element: "Supprimer un chiffre clé"
19 changes: 19 additions & 0 deletions src/Resources/views/Admin/UiElement/figures_ui_element.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{#
UI Element template
type: figures_ui_element
element fields:
- figures
- figure
- description
#}

<div class="ui grid segment">
{% for keyFigure in element.figures|default([]) %}
<div class="five wide column">
<strong>{{ keyFigure.figure }}</strong>
{% if keyFigure.description|default('') is not empty %}
<p>{{ keyFigure.description }}</p>
{% endif %}
</div>
{% endfor %}
</div>
19 changes: 19 additions & 0 deletions src/Resources/views/Shop/UiElement/figures_ui_element.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{#
UI Element template
type: figures_ui_element
element fields:
- figures
- figure
- description
#}

<div class="ui grid segment">
{% for keyFigure in element.figures|default([]) %}
<div class="five wide column">
<strong>{{ keyFigure.figure }}</strong>
{% if keyFigure.description|default('') is not empty %}
<p>{{ keyFigure.description }}</p>
{% endif %}
</div>
{% endfor %}
</div>
Loading