-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from monsieurbiz/feature/badge-ui-element
Add badge UI element
- Loading branch information
Showing
15 changed files
with
256 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?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\SyliusMediaManagerPlugin\Form\Type\ImageType as MediaManagerImageType; | ||
use Symfony\Component\Form\AbstractType; | ||
use Symfony\Component\Form\FormBuilderInterface; | ||
use Symfony\Component\Validator\Constraints as Assert; | ||
|
||
final class BadgeType 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' => true, | ||
'constraints' => [ | ||
new Assert\NotBlank(), | ||
], | ||
]) | ||
->add('image', MediaManagerImageType::class, [ | ||
'label' => 'monsieurbiz_ui_elements.common.fields.image', | ||
'required' => true, | ||
'constraints' => [ | ||
new Assert\NotBlank(), | ||
], | ||
]) | ||
->add('link', LinkType::class, [ | ||
'label' => 'monsieurbiz_ui_elements.common.fields.link', | ||
'required' => false, | ||
'with_label' => false, | ||
'attr' => [ | ||
'class' => 'ui segment', | ||
], | ||
]) | ||
; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?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\BadgeType; | ||
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.badges_ui_element', | ||
icon: 'th', | ||
title: 'monsieurbiz_ui_elements.ui_element.badges_ui_element.title', | ||
description: 'monsieurbiz_ui_elements.ui_element.badges_ui_element.description', | ||
templates: new TemplatesUiElement( | ||
adminRender: '@MonsieurBizSyliusUiElementsPlugin/Admin/UiElement/badges_ui_element.html.twig', | ||
frontRender: '@MonsieurBizSyliusUiElementsPlugin/Shop/UiElement/badges_ui_element.html.twig', | ||
), | ||
wireframe: 'badges', | ||
tags: [], | ||
)] | ||
class BadgesUiElementType extends AbstractType | ||
{ | ||
/** | ||
* @SuppressWarnings(PHPMD.UnusedFormalParameter) | ||
*/ | ||
public function buildForm(FormBuilderInterface $builder, array $options): void | ||
{ | ||
$builder | ||
->add('badges', CollectionType::class, [ | ||
'label' => 'monsieurbiz_ui_elements.ui_element.badges_ui_element.fields.badges', | ||
'entry_type' => BadgeType::class, | ||
'prototype_name' => '__badge__', | ||
'allow_add' => true, | ||
'allow_delete' => true, | ||
'constraints' => [ | ||
new Assert\Valid(), | ||
new Assert\Count(['min' => 1]), | ||
], | ||
'attr' => [ | ||
'class' => 'ui segment secondary collection--flex collection--flex-wide', | ||
], | ||
]) | ||
; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/Resources/views/Admin/UiElement/badges_ui_element.html.twig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
{# | ||
UI Element template | ||
type: figures_ui_element | ||
element fields: | ||
- badges | ||
- title | ||
- image | ||
- link | ||
- link | ||
- type | ||
#} | ||
|
||
{% if element.badges|default([])|length > 0 %} | ||
{% set columns = 'four' %} | ||
{% if element.badges|length == 3 %} | ||
{% set columns = 'three' %} | ||
{% endif %} | ||
{% if element.badges|length == 2 %} | ||
{% set columns = 'two' %} | ||
{% endif %} | ||
{% if element.badges|length == 1 %} | ||
{% set columns = 'one' %} | ||
{% endif %} | ||
<div class="ui grid stackable {{ columns }} columns" style="padding: 0 3vw;"> | ||
{% for badge in element.badges %} | ||
{% set isExternalLink = (badge.link.type|default(null)) == constant('MonsieurBiz\\SyliusUiElementsPlugin\\Form\\Type\\LinkType::TYPE_EXTERNAL') %} | ||
<div class="column"> | ||
{% if badge.link.link|default(null) is not empty %} | ||
<a href="{{ badge.link.link }}" {% if isExternalLink %}target="_blank" rel="noopener noreferrer"{% endif %}> | ||
{% endif %} | ||
<div class="ui card"> | ||
{% if badge.image|default(null) is not empty %} | ||
<div class="image"> | ||
<img src="{{ badge.image|imagine_filter('monsieurbiz_sylius_ui_elements_badges') }}"> | ||
</div> | ||
{% endif %} | ||
{% if badge.title|default(null) is not empty %} | ||
<div class="content"> | ||
{{ badge.title|raw }} | ||
</div> | ||
{% endif %} | ||
</div> | ||
{% if badge.link.link|default(null) is not empty %} | ||
</a> | ||
{% endif %} | ||
</div> | ||
{% endfor %} | ||
</div> | ||
{% endif %} |
13 changes: 0 additions & 13 deletions
13
src/Resources/views/Admin/UiElement/header_ui_element.html.twig
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.