-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(RichEditor): Form Extension to override ImageType et VideoType o…
…f RichEditorPlugin when used
- Loading branch information
Etienne Gutbub
committed
Apr 11, 2024
1 parent
bb3d946
commit 897037e
Showing
16 changed files
with
352 additions
and
0 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
22 changes: 22 additions & 0 deletions
22
dist/templates/bundles/MonsieurBizSyliusRichEditorPlugin/Admin/UiElement/image.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,22 @@ | ||
{# | ||
UI Element template | ||
type: image | ||
element fields : | ||
image | ||
alt | ||
title | ||
link | ||
align | ||
#} | ||
{% if element.image is defined %} | ||
{% set align = element.align is defined and element.align is not empty ? element.align : 'inherit' %} | ||
<p style="text-align: {{align}};"> | ||
{% if element.link is not empty %} | ||
<a href="{{ element.link }}"> | ||
<img class="ui fluid image" src="{{ get_media_manager_file_path(element.image) }}" alt="{{ element.alt|default('') }}" title="{{ element.title|default('') }}" /> | ||
</a> | ||
{% else %} | ||
<img class="ui fluid image" src="{{ get_media_manager_file_path(element.image) }}" alt="{{ element.alt|default('') }}" title="{{ element.title|default('') }}" /> | ||
{% endif %} | ||
</p> | ||
{% endif %} |
19 changes: 19 additions & 0 deletions
19
...ates/bundles/MonsieurBizSyliusRichEditorPlugin/Admin/UiElement/image_collection.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,19 @@ | ||
{# | ||
UI Element template | ||
type: image_collection | ||
element fields : | ||
images | ||
#} | ||
<div class="ui stackable two column grid"> | ||
{% for image in element.images %} | ||
<div class="column"> | ||
{% if image.link is not empty %} | ||
<a href="{{ image.link }}"> | ||
<img class="ui fluid image" src="{{ get_media_manager_file_path(image.image) }}" alt="{{ image.alt|default('') }}" title="{{ image.title|default('') }}" /> | ||
</a> | ||
{% else %} | ||
<img class="ui fluid image" src="{{ get_media_manager_file_path(image.image) }}" alt="{{ image.alt|default('') }}" title="{{ image.title|default('') }}" /> | ||
{% endif %} | ||
</div> | ||
{% endfor %} | ||
</div> |
14 changes: 14 additions & 0 deletions
14
dist/templates/bundles/MonsieurBizSyliusRichEditorPlugin/Admin/UiElement/video.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,14 @@ | ||
{# | ||
UI Element template | ||
type: video | ||
element fields : | ||
video | ||
image | ||
align | ||
#} | ||
{% set align = element.align is defined and element.align is not empty ? element.align : 'inherit' %} | ||
<div style="text-align: {{align}};"> | ||
<video width="100%" poster="{{ get_media_manager_file_path(element.image) }}" controls> | ||
<source src="{{ get_media_manager_file_path(element.video) }}" type="video/{{ element.video|split('.')|last }}"> | ||
</video> | ||
</div> |
22 changes: 22 additions & 0 deletions
22
dist/templates/bundles/MonsieurBizSyliusRichEditorPlugin/Shop/UiElement/image.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,22 @@ | ||
{# | ||
UI Element template | ||
type: image | ||
element fields : | ||
image | ||
alt | ||
title | ||
link | ||
align | ||
#} | ||
{% if element.image is defined %} | ||
{% set align = element.align is defined and element.align is not empty ? element.align : 'inherit' %} | ||
<p style="text-align: {{align}};"> | ||
{% if element.link is not empty %} | ||
<a href="{{ element.link }}"> | ||
<img class="ui fluid image" src="{{ get_media_manager_file_path(element.image) }}" alt="{{ element.alt|default('') }}" title="{{ element.title|default('') }}" /> | ||
</a> | ||
{% else %} | ||
<img class="ui fluid image" src="{{ get_media_manager_file_path(element.image) }}" alt="{{ element.alt|default('') }}" title="{{ element.title|default('') }}" /> | ||
{% endif %} | ||
</p> | ||
{% endif %} |
19 changes: 19 additions & 0 deletions
19
...lates/bundles/MonsieurBizSyliusRichEditorPlugin/Shop/UiElement/image_collection.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,19 @@ | ||
{# | ||
UI Element template | ||
type: image_collection | ||
element fields : | ||
images | ||
#} | ||
<div class="ui stackable two column grid"> | ||
{% for image in element.images %} | ||
<div class="column"> | ||
{% if image.link is not empty %} | ||
<a href="{{ image.link }}"> | ||
<img class="ui fluid image" src="{{ get_media_manager_file_path(image.image) }}" alt="{{ image.alt|default('') }}" title="{{ image.title|default('') }}" /> | ||
</a> | ||
{% else %} | ||
<img class="ui fluid image" src="{{ get_media_manager_file_path(image.image) }}" alt="{{ image.alt|default('') }}" title="{{ image.title|default('') }}" /> | ||
{% endif %} | ||
</div> | ||
{% endfor %} | ||
</div> |
14 changes: 14 additions & 0 deletions
14
dist/templates/bundles/MonsieurBizSyliusRichEditorPlugin/Shop/UiElement/video.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,14 @@ | ||
{# | ||
UI Element template | ||
type: video | ||
element fields : | ||
video | ||
image | ||
align | ||
#} | ||
{% set align = element.align is defined and element.align is not empty ? element.align : 'inherit' %} | ||
<div style="text-align: {{align}};"> | ||
<video width="100%" poster="{{ get_media_manager_file_path(element.image) }}" controls> | ||
<source src="{{ get_media_manager_file_path(element.video) }}" type="video/{{ element.video|split('.')|last }}"> | ||
</video> | ||
</div> |
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' Media Manager plugin for Sylius. | ||
* | ||
* (c) Monsieur Biz <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE.txt | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MonsieurBiz\SyliusMediaManagerPlugin\Form\Extension\RichEditor; | ||
|
||
use Closure; | ||
use MonsieurBiz\SyliusMediaManagerPlugin\Form\Type\ImageType as MediaManagerImageType; | ||
use MonsieurBiz\SyliusRichEditorPlugin\Form\Type\UiElement\ImageType as RichEditorImageType; | ||
use ReflectionFunction; | ||
use Symfony\Component\Form\AbstractTypeExtension; | ||
use Symfony\Component\Form\FormBuilderInterface; | ||
use Symfony\Component\Form\FormEvents; | ||
|
||
class ImageTypeExtension extends AbstractTypeExtension | ||
{ | ||
/** | ||
* @SuppressWarnings(UnusedFormalParameter) | ||
* @SuppressWarnings(CyclomaticComplexity) | ||
*/ | ||
public function buildForm(FormBuilderInterface $builder, array $options): void | ||
{ | ||
$builder | ||
->add('image', MediaManagerImageType::class) | ||
; | ||
|
||
foreach ($builder->getEventDispatcher()->getListeners(FormEvents::PRE_SUBMIT) as $listener) { | ||
if ($listener instanceof Closure) { | ||
$reflection = new ReflectionFunction($listener); | ||
$closureScopeClass = $reflection->getClosureScopeClass(); | ||
|
||
if (null === $closureScopeClass) { | ||
continue; | ||
} | ||
/** @phpstan-ignore-next-line */ | ||
if (RichEditorImageType::class === $closureScopeClass->getName()) { | ||
// Remove the event listener that is re-adding the field and emptying the options | ||
$builder->getEventDispatcher()->removeListener(FormEvents::PRE_SUBMIT, $listener); | ||
} | ||
} | ||
} | ||
} | ||
|
||
public static function getExtendedTypes(): iterable | ||
{ | ||
/** @phpstan-ignore-next-line */ | ||
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,60 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Monsieur Biz' Media Manager plugin for Sylius. | ||
* | ||
* (c) Monsieur Biz <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE.txt | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MonsieurBiz\SyliusMediaManagerPlugin\Form\Extension\RichEditor; | ||
|
||
use Closure; | ||
use MonsieurBiz\SyliusMediaManagerPlugin\Form\Type\ImageType as MediaManagerImageType; | ||
use MonsieurBiz\SyliusMediaManagerPlugin\Form\Type\VideoType as MediaManagerVideoType; | ||
use MonsieurBiz\SyliusRichEditorPlugin\Form\Type\UiElement\VideoType as RichEditorVideoType; | ||
use ReflectionFunction; | ||
use Symfony\Component\Form\AbstractTypeExtension; | ||
use Symfony\Component\Form\FormBuilderInterface; | ||
use Symfony\Component\Form\FormEvents; | ||
|
||
class VideoTypeExtension extends AbstractTypeExtension | ||
{ | ||
/** | ||
* @SuppressWarnings(UnusedFormalParameter) | ||
* @SuppressWarnings(CyclomaticComplexity) | ||
*/ | ||
public function buildForm(FormBuilderInterface $builder, array $options): void | ||
{ | ||
$builder | ||
->add('video', MediaManagerVideoType::class) | ||
->add('image', MediaManagerImageType::class) | ||
; | ||
|
||
foreach ($builder->getEventDispatcher()->getListeners(FormEvents::PRE_SUBMIT) as $listener) { | ||
if ($listener instanceof Closure) { | ||
$reflection = new ReflectionFunction($listener); | ||
$closureScopeClass = $reflection->getClosureScopeClass(); | ||
|
||
if (null === $closureScopeClass) { | ||
continue; | ||
} | ||
/** @phpstan-ignore-next-line */ | ||
if (RichEditorVideoType::class === $closureScopeClass->getName()) { | ||
// Remove the event listener that is re-adding the field and emptying the options | ||
$builder->getEventDispatcher()->removeListener(FormEvents::PRE_SUBMIT, $listener); | ||
} | ||
} | ||
} | ||
} | ||
|
||
public static function getExtendedTypes(): iterable | ||
{ | ||
/** @phpstan-ignore-next-line */ | ||
return [RichEditorVideoType::class]; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/Resources/views/MonsieurBizSyliusRichEditorPlugin/Admin/UiElement/image.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,22 @@ | ||
{# | ||
UI Element template | ||
type: image | ||
element fields : | ||
image | ||
alt | ||
title | ||
link | ||
align | ||
#} | ||
{% if element.image is defined %} | ||
{% set align = element.align is defined and element.align is not empty ? element.align : 'inherit' %} | ||
<p style="text-align: {{align}};"> | ||
{% if element.link is not empty %} | ||
<a href="{{ element.link }}"> | ||
<img class="ui fluid image" src="{{ get_media_manager_file_path(element.image) }}" alt="{{ element.alt|default('') }}" title="{{ element.title|default('') }}" /> | ||
</a> | ||
{% else %} | ||
<img class="ui fluid image" src="{{ get_media_manager_file_path(element.image) }}" alt="{{ element.alt|default('') }}" title="{{ element.title|default('') }}" /> | ||
{% endif %} | ||
</p> | ||
{% endif %} |
19 changes: 19 additions & 0 deletions
19
...ources/views/MonsieurBizSyliusRichEditorPlugin/Admin/UiElement/image_collection.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,19 @@ | ||
{# | ||
UI Element template | ||
type: image_collection | ||
element fields : | ||
images | ||
#} | ||
<div class="ui stackable two column grid"> | ||
{% for image in element.images %} | ||
<div class="column"> | ||
{% if image.link is not empty %} | ||
<a href="{{ image.link }}"> | ||
<img class="ui fluid image" src="{{ get_media_manager_file_path(image.image) }}" alt="{{ image.alt|default('') }}" title="{{ image.title|default('') }}" /> | ||
</a> | ||
{% else %} | ||
<img class="ui fluid image" src="{{ get_media_manager_file_path(image.image) }}" alt="{{ image.alt|default('') }}" title="{{ image.title|default('') }}" /> | ||
{% endif %} | ||
</div> | ||
{% endfor %} | ||
</div> |
14 changes: 14 additions & 0 deletions
14
src/Resources/views/MonsieurBizSyliusRichEditorPlugin/Admin/UiElement/video.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,14 @@ | ||
{# | ||
UI Element template | ||
type: video | ||
element fields : | ||
video | ||
image | ||
align | ||
#} | ||
{% set align = element.align is defined and element.align is not empty ? element.align : 'inherit' %} | ||
<div style="text-align: {{align}};"> | ||
<video width="100%" poster="{{ get_media_manager_file_path(element.image) }}" controls> | ||
<source src="{{ get_media_manager_file_path(element.video) }}" type="video/{{ element.video|split('.')|last }}"> | ||
</video> | ||
</div> |
22 changes: 22 additions & 0 deletions
22
src/Resources/views/MonsieurBizSyliusRichEditorPlugin/Shop/UiElement/image.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,22 @@ | ||
{# | ||
UI Element template | ||
type: image | ||
element fields : | ||
image | ||
alt | ||
title | ||
link | ||
align | ||
#} | ||
{% if element.image is defined %} | ||
{% set align = element.align is defined and element.align is not empty ? element.align : 'inherit' %} | ||
<p style="text-align: {{align}};"> | ||
{% if element.link is not empty %} | ||
<a href="{{ element.link }}"> | ||
<img class="ui fluid image" src="{{ get_media_manager_file_path(element.image) }}" alt="{{ element.alt|default('') }}" title="{{ element.title|default('') }}" /> | ||
</a> | ||
{% else %} | ||
<img class="ui fluid image" src="{{ get_media_manager_file_path(element.image) }}" alt="{{ element.alt|default('') }}" title="{{ element.title|default('') }}" /> | ||
{% endif %} | ||
</p> | ||
{% endif %} |
19 changes: 19 additions & 0 deletions
19
...sources/views/MonsieurBizSyliusRichEditorPlugin/Shop/UiElement/image_collection.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,19 @@ | ||
{# | ||
UI Element template | ||
type: image_collection | ||
element fields : | ||
images | ||
#} | ||
<div class="ui stackable two column grid"> | ||
{% for image in element.images %} | ||
<div class="column"> | ||
{% if image.link is not empty %} | ||
<a href="{{ image.link }}"> | ||
<img class="ui fluid image" src="{{ get_media_manager_file_path(image.image) }}" alt="{{ image.alt|default('') }}" title="{{ image.title|default('') }}" /> | ||
</a> | ||
{% else %} | ||
<img class="ui fluid image" src="{{ get_media_manager_file_path(image.image) }}" alt="{{ image.alt|default('') }}" title="{{ image.title|default('') }}" /> | ||
{% endif %} | ||
</div> | ||
{% endfor %} | ||
</div> |
14 changes: 14 additions & 0 deletions
14
src/Resources/views/MonsieurBizSyliusRichEditorPlugin/Shop/UiElement/video.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,14 @@ | ||
{# | ||
UI Element template | ||
type: video | ||
element fields : | ||
video | ||
image | ||
align | ||
#} | ||
{% set align = element.align is defined and element.align is not empty ? element.align : 'inherit' %} | ||
<div style="text-align: {{align}};"> | ||
<video width="100%" poster="{{ get_media_manager_file_path(element.image) }}" controls> | ||
<source src="{{ get_media_manager_file_path(element.video) }}" type="video/{{ element.video|split('.')|last }}"> | ||
</video> | ||
</div> |