-
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.
- Loading branch information
1 parent
a50ec39
commit 5470906
Showing
13 changed files
with
354 additions
and
7 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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
parameters: | ||
level: max | ||
level: 8 | ||
paths: | ||
- %rootDir%/src/ | ||
|
||
|
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,74 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Monsieur Biz's Blog plugin 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\SyliusBlogPlugin\Form\Type; | ||
|
||
use MonsieurBiz\SyliusBlogPlugin\Entity\Article; | ||
use MonsieurBiz\SyliusBlogPlugin\Entity\ArticleInterface; | ||
use MonsieurBiz\SyliusBlogPlugin\Repository\ArticleRepositoryInterface; | ||
use Sylius\Bundle\ResourceBundle\Form\DataTransformer\ResourceToIdentifierTransformer; | ||
use Sylius\Component\Channel\Context\ChannelContextInterface; | ||
use Sylius\Component\Locale\Context\LocaleContextInterface; | ||
use Symfony\Bridge\Doctrine\Form\Type\EntityType; | ||
use Symfony\Component\Form\AbstractType; | ||
use Symfony\Component\Form\Extension\Core\Type\IntegerType; | ||
use Symfony\Component\Form\FormBuilderInterface; | ||
use Symfony\Component\Form\ReversedTransformer; | ||
use Symfony\Component\Validator\Constraints as Assert; | ||
|
||
final class CaseStudyElementType extends AbstractType | ||
{ | ||
/** @phpstan-ignore-next-line */ | ||
public function __construct( | ||
private ArticleRepositoryInterface $articleRepository, | ||
private ChannelContextInterface $channelContext, | ||
private LocaleContextInterface $localeContext, | ||
) { | ||
} | ||
|
||
/** | ||
* @SuppressWarnings(PHPMD.UnusedFormalParameter) | ||
*/ | ||
public function buildForm(FormBuilderInterface $builder, array $options): void | ||
{ | ||
$caseStudies = $this->articleRepository->createShopListQueryBuilderByType( | ||
$this->localeContext->getLocaleCode(), | ||
ArticleInterface::CASE_STUDY_TYPE, | ||
$this->channelContext->getChannel(), | ||
null | ||
); | ||
|
||
$caseStudies = $caseStudies->orderBy('translation.title')->getQuery()->getResult(); | ||
|
||
$builder | ||
->add('case_study', EntityType::class, [ | ||
'class' => Article::class, | ||
'label' => 'monsieurbiz_blog.ui_element.case_studies_ui_element.fields.case_study', | ||
'choice_label' => fn (Article $caseStudy) => $caseStudy->getTitle(), | ||
'choice_value' => fn (?Article $caseStudy) => $caseStudy ? $caseStudy->getId() : null, | ||
'required' => true, | ||
'choices' => $caseStudies, | ||
]) | ||
->add('position', IntegerType::class, [ | ||
'label' => 'monsieurbiz_blog.ui_element.case_studies_ui_element.fields.position', | ||
'required' => true, | ||
'constraints' => [ | ||
new Assert\NotBlank(), | ||
new Assert\GreaterThan(0), | ||
], | ||
]) | ||
; | ||
|
||
$builder->get('case_study')->addModelTransformer( | ||
new ReversedTransformer(new ResourceToIdentifierTransformer($this->articleRepository, 'id')), | ||
); | ||
} | ||
} |
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,66 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Monsieur Biz's Blog plugin 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\SyliusBlogPlugin\Form\Type\UiElement; | ||
|
||
use MonsieurBiz\SyliusBlogPlugin\Form\Type\CaseStudyElementType; | ||
use MonsieurBiz\SyliusRichEditorPlugin\Attribute\AsUiElement; | ||
use MonsieurBiz\SyliusRichEditorPlugin\Attribute\TemplatesUiElement; | ||
use Symfony\Component\Form\AbstractType; | ||
use Symfony\Component\Form\Extension\Core\Type\CollectionType; | ||
use Symfony\Component\Form\Extension\Core\Type\TextType; | ||
use Symfony\Component\Form\FormBuilderInterface; | ||
use Symfony\Component\Validator\Constraints as Assert; | ||
|
||
#[AsUiElement( | ||
code: 'monsieurbiz_blog.case_studies_ui_element', | ||
icon: 'crosshairs', | ||
uiElement: 'MonsieurBiz\SyliusBlogPlugin\UiElement\CaseStudiesUiElement', | ||
title: 'monsieurbiz_blog.ui_element.case_studies_ui_element.title', | ||
description: 'monsieurbiz_blog.ui_element.case_studies_ui_element.description', | ||
templates: new TemplatesUiElement( | ||
adminRender: '@MonsieurBizSyliusBlogPlugin/Admin/UiElement/case_studies.html.twig', | ||
frontRender: '@MonsieurBizSyliusBlogPlugin/Shop/UiElement/case_studies.html.twig', | ||
), | ||
tags: [], | ||
wireframe: 'case-studies', | ||
)] | ||
class CaseStudiesUiElementType extends AbstractType | ||
{ | ||
/** | ||
* @SuppressWarnings(PHPMD.UnusedFormalParameter) | ||
*/ | ||
public function buildForm(FormBuilderInterface $builder, array $options): void | ||
{ | ||
$builder | ||
->add('title', TextType::class, [ | ||
'label' => 'monsieurbiz_blog.ui_element.case_studies_ui_element.fields.title', | ||
'required' => false, | ||
]) | ||
->add('case_studies', CollectionType::class, [ | ||
'label' => 'monsieurbiz_blog.ui_element.case_studies_ui_element.fields.case_studies', | ||
'entry_type' => CaseStudyElementType::class, | ||
'prototype_name' => '__case_study__', | ||
'allow_add' => true, | ||
'allow_delete' => true, | ||
'by_reference' => false, | ||
'delete_empty' => true, | ||
'attr' => [ | ||
'class' => 'ui segment secondary collection--flex', | ||
], | ||
'constraints' => [ | ||
new Assert\Count(['min' => 1]), | ||
new Assert\Valid(), | ||
], | ||
]) | ||
; | ||
} | ||
} |
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
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,18 @@ | ||
{% set filter = filter|default('monsieurbiz_blog_image_thumbnail') %} | ||
{% set placeholder = placeholder|default('200x200.png') %} | ||
|
||
{# Thumbnail display #} | ||
{% if article.thumbnailImage and filter == 'monsieurbiz_blog_image_thumbnail' %} | ||
{% set path = article.thumbnailImage|imagine_filter(filter) %} | ||
{# Image display or thumbnail fallback on image #} | ||
{% elseif article.image %} | ||
{% set path = article.image|imagine_filter(filter) %} | ||
{% else %} | ||
{% if use_webpack %} | ||
{% set path = asset('build/shop/images/' ~ placeholder, 'shop') %} | ||
{% else %} | ||
{% set path = asset('assets/shop/img/' ~ placeholder) %} | ||
{% endif %} | ||
{% endif %} | ||
|
||
<img src="{{ path }}" alt="{{ article.title }}"> |
41 changes: 41 additions & 0 deletions
41
src/Resources/views/Admin/UiElement/case_studies.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,41 @@ | ||
{# | ||
UI Element template | ||
type: case_studies | ||
element fields : | ||
title | ||
case_studies | ||
element methods: | ||
getCaseStudies | ||
#} | ||
{% import '@SyliusUi/Macro/messages.html.twig' as messages %} | ||
|
||
{% set case_studies = ui_element.getCaseStudies(element) %} | ||
|
||
{% if case_studies|length > 0 %} | ||
|
||
{% if element.title|default('') is not empty %} | ||
<div class="ui huge header"> | ||
{{ element.title }} | ||
</div> | ||
{% endif %} | ||
|
||
<div class="ui cards"> | ||
{% for case_study in case_studies %} | ||
<div class="ui card"> | ||
<div class="image"> | ||
{% include '@MonsieurBizSyliusBlogPlugin/Admin/Article/_image.html.twig' with { 'article' : case_study} %} | ||
</div> | ||
<div class="content"> | ||
<a class="header">{{ case_study.title }}</a><br /> | ||
<div class="extra content"> | ||
<a class="ui button" href="{{ path('monsieurbiz_case_studies_article_show', {'slug': case_study.slug}) }}"> | ||
{{ 'monsieurbiz_blog.ui.read_more'|trans }} | ||
</a> | ||
</div> | ||
</div> | ||
</div> | ||
{% endfor %} | ||
</div> | ||
{% else %} | ||
{{ messages.info('monsieurbiz_blog.ui.no_results_to_display') }} | ||
{% endif %} |
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,39 @@ | ||
{# | ||
UI Element template | ||
type: case_studies | ||
element fields : | ||
title | ||
case_studies | ||
element methods: | ||
getCaseStudies | ||
#} | ||
{% import '@SyliusUi/Macro/messages.html.twig' as messages %} | ||
|
||
{% set case_studies = ui_element.getCaseStudies(element) %} | ||
|
||
{% if case_studies|length > 0 %} | ||
|
||
{% if element.title|default('') is not empty %} | ||
<div class="ui huge header"> | ||
{{ element.title }} | ||
</div> | ||
{% endif %} | ||
|
||
<div class="ui cards"> | ||
{% for case_study in case_studies %} | ||
<div class="ui card"> | ||
<div class="image"> | ||
{% include '@MonsieurBizSyliusBlogPlugin/Admin/Article/_image.html.twig' with { 'article' : case_study} %} | ||
</div> | ||
<div class="content"> | ||
<a class="header">{{ case_study.title }}</a><br /> | ||
<div class="extra content"> | ||
<a class="ui button" href="{{ path('monsieurbiz_case_studies_article_show', {'slug': case_study.slug}) }}"> | ||
{{ 'monsieurbiz_blog.ui.read_more'|trans }} | ||
</a> | ||
</div> | ||
</div> | ||
</div> | ||
{% endfor %} | ||
</div> | ||
{% endif %} |
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,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> |
Oops, something went wrong.