-
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 branch 'master' into feature/quote-with-link
- Loading branch information
Showing
7 changed files
with
193 additions
and
3 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
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,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; | ||
|
||
use MonsieurBiz\SyliusRichEditorPlugin\Form\Type\UiElement\ImageType as RichEditorImageType; | ||
use Symfony\Component\Form\AbstractType; | ||
use Symfony\Component\Form\FormBuilderInterface; | ||
use Symfony\Component\OptionsResolver\OptionsResolver; | ||
|
||
class ImageType extends AbstractType | ||
{ | ||
/** | ||
* @inheritdoc | ||
*/ | ||
public function buildForm(FormBuilderInterface $builder, array $options): void | ||
{ | ||
if (!$options['with_link']) { | ||
$builder->remove('link'); | ||
} | ||
if (!$options['with_alignment']) { | ||
$builder->remove('align'); | ||
} | ||
} | ||
|
||
public function configureOptions(OptionsResolver $resolver): void | ||
{ | ||
$resolver->setDefaults([ | ||
'with_link' => true, | ||
'with_alignment' => true, | ||
]); | ||
$resolver->setAllowedTypes('with_link', ['null', 'bool']); | ||
$resolver->setAllowedTypes('with_alignment', ['null', 'bool']); | ||
} | ||
|
||
public function getParent(): string | ||
{ | ||
return RichEditorImageType::class; | ||
} | ||
} |
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,72 @@ | ||
<?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\SyliusRichEditorPlugin\Form\Type\WysiwygType; | ||
use MonsieurBiz\SyliusUiElementsPlugin\Form\Type\ImageType; | ||
use Symfony\Component\Form\AbstractType; | ||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; | ||
use Symfony\Component\Form\FormBuilderInterface; | ||
use Symfony\Component\Validator\Constraints as Assert; | ||
|
||
#[AsUiElement( | ||
code: 'monsieurbiz_ui_elements.text_with_image_ui_element', | ||
icon: 'indent', | ||
title: 'monsieurbiz_ui_elements.ui_element.text_with_image_ui_element.title', | ||
description: 'monsieurbiz_ui_elements.ui_element.text_with_image_ui_element.description', | ||
templates: new TemplatesUiElement( | ||
adminRender: '@MonsieurBizSyliusUiElementsPlugin/Admin/UiElement/text_with_image_ui_element.html.twig', | ||
frontRender: '@MonsieurBizSyliusUiElementsPlugin/Front/UiElement/text_with_image_ui_element.html.twig', | ||
), | ||
tags: [], | ||
)] | ||
class TextWithImageUiElementType extends AbstractType | ||
{ | ||
public const IMAGE_POSITION_LEFT = 'left'; | ||
|
||
public const IMAGE_POSITION_RIGHT = 'right'; | ||
|
||
/** | ||
* @SuppressWarnings(PHPMD.UnusedFormalParameter) | ||
*/ | ||
public function buildForm(FormBuilderInterface $builder, array $options): void | ||
{ | ||
$builder | ||
->add('content', WysiwygType::class, [ | ||
'label' => 'monsieurbiz_ui_elements.common.fields.content', | ||
'required' => true, | ||
'constraints' => [ | ||
new Assert\NotBlank(), | ||
], | ||
]) | ||
->add('image', ImageType::class, [ | ||
'label' => 'monsieurbiz_richeditor_plugin.ui_element.monsieurbiz.image.field.image', | ||
'required' => true, | ||
'with_link' => false, | ||
'with_alignment' => false, | ||
]) | ||
->add('imageAlign', ChoiceType::class, [ | ||
'label' => 'monsieurbiz_ui_elements.common.fields.alignment', | ||
'required' => true, | ||
'choices' => [ | ||
'monsieurbiz_ui_elements.ui_element.text_with_image_ui_element.fields.image_align.choices.left' => self::IMAGE_POSITION_LEFT, | ||
'monsieurbiz_ui_elements.ui_element.text_with_image_ui_element.fields.image_align.choices.right' => self::IMAGE_POSITION_RIGHT, | ||
], | ||
'constraints' => [ | ||
new Assert\NotBlank(), | ||
], | ||
]) | ||
; | ||
} | ||
} |
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
25 changes: 25 additions & 0 deletions
25
src/Resources/views/Admin/UiElement/text_with_image_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,25 @@ | ||
{# | ||
UI Element template | ||
type: text_with_image_ui_element | ||
element fields: | ||
- content | ||
- image | ||
- image | ||
- alt | ||
- title | ||
- imageAlign | ||
#} | ||
|
||
<div class="ui"> | ||
<div class="content"> | ||
{{ element.content|raw }} | ||
</div> | ||
<img src="{{ element.image.image }}" alt="{{ element.image.alt ?? '' }}" title="{{ element.image.title ?? '' }}" class="ui image"> | ||
<div class="extra content"> | ||
<ul> | ||
<li> | ||
{{ 'monsieurbiz_ui_elements.common.fields.alignment'|trans }} : {{ element.imageAlign }} | ||
</li> | ||
</ul> | ||
</div> | ||
</div> |
25 changes: 25 additions & 0 deletions
25
src/Resources/views/Shop/UiElement/text_with_image_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,25 @@ | ||
{# | ||
UI Element template | ||
type: text_with_image_ui_element | ||
element fields: | ||
- content | ||
- image | ||
- image | ||
- alt | ||
- title | ||
- imageAlign | ||
#} | ||
|
||
<div class="ui"> | ||
<div class="content"> | ||
{{ element.content|raw }} | ||
</div> | ||
<img src="{{ element.image.image }}" alt="{{ element.image.alt ?? '' }}" title="{{ element.image.title ?? '' }}" class="ui image"> | ||
<div class="extra content"> | ||
<ul> | ||
<li> | ||
{{ 'monsieurbiz_ui_elements.common.fields.alignment'|trans }} : {{ element.imageAlign }} | ||
</li> | ||
</ul> | ||
</div> | ||
</div> |