Skip to content

Commit

Permalink
OP-327: Redesign twig functions
Browse files Browse the repository at this point in the history
  • Loading branch information
jkindly committed Jul 16, 2024
1 parent 6da89f6 commit 0b3e0c3
Show file tree
Hide file tree
Showing 34 changed files with 585 additions and 32 deletions.
10 changes: 0 additions & 10 deletions src/Entity/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,4 @@ public function setName(?string $name): void
{
$this->name = $name;
}

public function getContent(): ?string
{
$content = '';
foreach ($this->contentElements as $contentElement) {
$content .= $contentElement->getContent() . \PHP_EOL;
}

return $content;
}
}
3 changes: 1 addition & 2 deletions src/Entity/BlockInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ interface BlockInterface extends
CollectibleInterface,
ChannelsAwareInterface,
ContentConfigurationAwareInterface,
LocaleAwareInterface,
ContentableInterface
LocaleAwareInterface
{
public function getCode(): ?string;

Expand Down
11 changes: 0 additions & 11 deletions src/Entity/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,4 @@ protected function createTranslation(): PageTranslationInterface
{
return new PageTranslation();
}

public function getContent(): ?string
{
$content = '';
/** @var ContentConfigurationInterface $contentElement */
foreach ($this->contentElements as $contentElement) {
$content .= $contentElement->getContent() . \PHP_EOL;
}

return $content;
}
}
3 changes: 1 addition & 2 deletions src/Entity/PageInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ interface PageInterface extends
ChannelsAwareInterface,
SlugAwareInterface,
ContentConfigurationAwareInterface,
LocaleAwareInterface,
ContentableInterface
LocaleAwareInterface
{
public function getCode(): ?string;

Expand Down
20 changes: 20 additions & 0 deletions src/Renderer/ContentElement/ContentElementRendererInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

/*
* This file was created by developers working at BitBag
* Do you need more information about us and what we do? Visit our https://bitbag.io website!
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
*/

declare(strict_types=1);

namespace BitBag\SyliusCmsPlugin\Renderer\ContentElement;

use BitBag\SyliusCmsPlugin\Entity\ContentConfigurationInterface;

interface ContentElementRendererInterface
{
public function supports(ContentConfigurationInterface $contentConfiguration): bool;

public function render(ContentConfigurationInterface $contentConfiguration): string;
}
40 changes: 40 additions & 0 deletions src/Renderer/ContentElement/HeadingContentElementRenderer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

/*
* This file was created by developers working at BitBag
* Do you need more information about us and what we do? Visit our https://bitbag.io website!
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
*/

declare(strict_types=1);

namespace BitBag\SyliusCmsPlugin\Renderer\ContentElement;

use BitBag\SyliusCmsPlugin\Entity\ContentConfigurationInterface;
use BitBag\SyliusCmsPlugin\Form\Type\ContentElements\HeadingContentElementType;
use Twig\Environment;

final class HeadingContentElementRenderer implements ContentElementRendererInterface
{
public function __construct(private Environment $twig)
{
}

public function supports(ContentConfigurationInterface $contentConfiguration): bool
{
return HeadingContentElementType::TYPE === $contentConfiguration->getType();
}

public function render(ContentConfigurationInterface $contentConfiguration): string
{
$configuration = $contentConfiguration->getConfiguration();
$headingType = $configuration['heading_type'];
$headingContent = $configuration['heading'];

return $this->twig->render('@BitBagSyliusCmsPlugin/Shop/ContentElement/index.html.twig', [
'content_element' => '@BitBagSyliusCmsPlugin/Shop/ContentElement/_heading.html.twig',
'heading_type' => $headingType,
'heading_content' => $headingContent,
]);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

/*
* This file was created by developers working at BitBag
* Do you need more information about us and what we do? Visit our https://bitbag.io website!
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
*/

declare(strict_types=1);

namespace BitBag\SyliusCmsPlugin\Renderer\ContentElement;

use BitBag\SyliusCmsPlugin\Entity\ContentConfigurationInterface;
use BitBag\SyliusCmsPlugin\Form\Type\ContentElements\MultipleMediaContentElementType;
use BitBag\SyliusCmsPlugin\Twig\Runtime\RenderMediaRuntimeInterface;
use Twig\Environment;

final class MultipleMediaContentElementRenderer implements ContentElementRendererInterface
{
public function __construct(
private Environment $twig,
private RenderMediaRuntimeInterface $renderMediaRuntime,
) {
}

public function supports(ContentConfigurationInterface $contentConfiguration): bool
{
return MultipleMediaContentElementType::TYPE === $contentConfiguration->getType();
}

public function render(ContentConfigurationInterface $contentConfiguration): string
{
$media = [];
$codes = $contentConfiguration->getConfiguration()['multiple_media'];
foreach ($codes as $code) {
$media[] = $this->renderMediaRuntime->renderMedia($code);
}

return $this->twig->render('@BitBagSyliusCmsPlugin/Shop/ContentElement/index.html.twig', [
'content_element' => '@BitBagSyliusCmsPlugin/Shop/ContentElement/_multiple_media.html.twig',
'media' => $media,
]);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

/*
* This file was created by developers working at BitBag
* Do you need more information about us and what we do? Visit our https://bitbag.io website!
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
*/

declare(strict_types=1);

namespace BitBag\SyliusCmsPlugin\Renderer\ContentElement;

use BitBag\SyliusCmsPlugin\Entity\ContentConfigurationInterface;
use BitBag\SyliusCmsPlugin\Form\Type\ContentElements\ProductsCarouselByTaxonContentElementType;
use Sylius\Component\Core\Model\TaxonInterface;
use Sylius\Component\Core\Repository\ProductRepositoryInterface;
use Sylius\Component\Taxonomy\Repository\TaxonRepositoryInterface;
use Twig\Environment;

final class ProductsCarouselByTaxonContentElementRenderer implements ContentElementRendererInterface
{
public function __construct(
private Environment $twig,
private ProductRepositoryInterface $productRepository,
private TaxonRepositoryInterface $taxonRepository,
) {
}

public function supports(ContentConfigurationInterface $contentConfiguration): bool
{
return ProductsCarouselByTaxonContentElementType::TYPE === $contentConfiguration->getType();
}

public function render(ContentConfigurationInterface $contentConfiguration): string
{
$taxonCode = $contentConfiguration->getConfiguration()['products_carousel_by_taxon'];

/** @var TaxonInterface $taxon */
$taxon = $this->taxonRepository->findOneBy(['code' => $taxonCode]);
$products = $this->productRepository->findByTaxon($taxon);

return $this->twig->render('@BitBagSyliusCmsPlugin/Shop/ContentElement/index.html.twig', [
'content_element' => '@BitBagSyliusCmsPlugin/Shop/ContentElement/_products_carousel.html.twig',
'products' => $products,
]);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

/*
* This file was created by developers working at BitBag
* Do you need more information about us and what we do? Visit our https://bitbag.io website!
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
*/

declare(strict_types=1);

namespace BitBag\SyliusCmsPlugin\Renderer\ContentElement;

use BitBag\SyliusCmsPlugin\Entity\ContentConfigurationInterface;
use BitBag\SyliusCmsPlugin\Form\Type\ContentElements\ProductsCarouselContentElementType;
use Sylius\Component\Core\Repository\ProductRepositoryInterface;
use Twig\Environment;

final class ProductsCarouselContentElementRenderer implements ContentElementRendererInterface
{
public function __construct(
private Environment $twig,
private ProductRepositoryInterface $productRepository,
) {
}

public function supports(ContentConfigurationInterface $contentConfiguration): bool
{
return ProductsCarouselContentElementType::TYPE === $contentConfiguration->getType();
}

public function render(ContentConfigurationInterface $contentConfiguration): string
{
$configuration = $contentConfiguration->getConfiguration();
$productsCodes = $configuration['products_carousel']['products'];
$products = $this->productRepository->findBy(['code' => $productsCodes]);

return $this->twig->render('@BitBagSyliusCmsPlugin/Shop/ContentElement/index.html.twig', [
'content_element' => '@BitBagSyliusCmsPlugin/Shop/ContentElement/_products_carousel.html.twig',
'products' => $products,
]);
}
}
40 changes: 40 additions & 0 deletions src/Renderer/ContentElement/SingleMediaContentElementRenderer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

/*
* This file was created by developers working at BitBag
* Do you need more information about us and what we do? Visit our https://bitbag.io website!
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
*/

declare(strict_types=1);

namespace BitBag\SyliusCmsPlugin\Renderer\ContentElement;

use BitBag\SyliusCmsPlugin\Entity\ContentConfigurationInterface;
use BitBag\SyliusCmsPlugin\Form\Type\ContentElements\SingleMediaContentElementType;
use BitBag\SyliusCmsPlugin\Twig\Runtime\RenderMediaRuntimeInterface;
use Twig\Environment;

final class SingleMediaContentElementRenderer implements ContentElementRendererInterface
{
public function __construct(
private Environment $twig,
private RenderMediaRuntimeInterface $renderMediaRuntime,
) {
}

public function supports(ContentConfigurationInterface $contentConfiguration): bool
{
return SingleMediaContentElementType::TYPE === $contentConfiguration->getType();
}

public function render(ContentConfigurationInterface $contentConfiguration): string
{
$code = $contentConfiguration->getConfiguration()['single_media'];

return $this->twig->render('@BitBagSyliusCmsPlugin/Shop/ContentElement/index.html.twig', [
'content_element' => '@BitBagSyliusCmsPlugin/Shop/ContentElement/_single_media.html.twig',
'media' => $this->renderMediaRuntime->renderMedia($code),
]);
}
}
42 changes: 42 additions & 0 deletions src/Renderer/ContentElement/TaxonsListContentElementRenderer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

/*
* This file was created by developers working at BitBag
* Do you need more information about us and what we do? Visit our https://bitbag.io website!
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
*/

declare(strict_types=1);

namespace BitBag\SyliusCmsPlugin\Renderer\ContentElement;

use BitBag\SyliusCmsPlugin\Entity\ContentConfigurationInterface;
use BitBag\SyliusCmsPlugin\Form\Type\ContentElements\TaxonsListContentElementType;
use Sylius\Component\Taxonomy\Repository\TaxonRepositoryInterface;
use Twig\Environment;

final class TaxonsListContentElementRenderer implements ContentElementRendererInterface
{
public function __construct(
private Environment $twig,
private TaxonRepositoryInterface $taxonRepository,
) {
}

public function supports(ContentConfigurationInterface $contentConfiguration): bool
{
return TaxonsListContentElementType::TYPE === $contentConfiguration->getType();
}

public function render(ContentConfigurationInterface $contentConfiguration): string
{
$configuration = $contentConfiguration->getConfiguration();
$taxonsCodes = $configuration['taxons_list']['taxons'];
$taxons = $this->taxonRepository->findBy(['code' => $taxonsCodes]);

return $this->twig->render('@BitBagSyliusCmsPlugin/Shop/ContentElement/index.html.twig', [
'content_element' => '@BitBagSyliusCmsPlugin/Shop/ContentElement/_taxons_list.html.twig',
'taxons' => $taxons,
]);
}
}
35 changes: 35 additions & 0 deletions src/Renderer/ContentElement/TextareaContentElementRenderer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

/*
* This file was created by developers working at BitBag
* Do you need more information about us and what we do? Visit our https://bitbag.io website!
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
*/

declare(strict_types=1);

namespace BitBag\SyliusCmsPlugin\Renderer\ContentElement;

use BitBag\SyliusCmsPlugin\Entity\ContentConfigurationInterface;
use BitBag\SyliusCmsPlugin\Form\Type\ContentElements\TextareaContentElementType;
use Twig\Environment;

final class TextareaContentElementRenderer implements ContentElementRendererInterface
{
public function __construct(private Environment $twig)
{
}

public function supports(ContentConfigurationInterface $contentConfiguration): bool
{
return TextareaContentElementType::TYPE === $contentConfiguration->getType();
}

public function render(ContentConfigurationInterface $contentConfiguration): string
{
return $this->twig->render('@BitBagSyliusCmsPlugin/Shop/ContentElement/index.html.twig', [
'content_element' => '@BitBagSyliusCmsPlugin/Shop/ContentElement/_textarea.html.twig',
'content' => $contentConfiguration->getConfiguration()['textarea'],
]);
}
}
27 changes: 27 additions & 0 deletions src/Resources/assets/shop/scss/_carousel.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
.carousel-wrapper {
position: relative;

.carousel {
margin: 0 -1em;
}

.carousel-nav {
.carousel-left {
left: 30px;
}

.carousel-right {
right: 30px;
}

.carousel-left, .carousel-right {
position: absolute;
top: 50%;
transform: translateY(-50%);
}
}

.carousel-item {
padding: 5px 1em;
}
}
1 change: 1 addition & 0 deletions src/Resources/assets/shop/scss/main.scss
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
@import './block/main.scss';
@import 'carousel';
Loading

0 comments on commit 0b3e0c3

Please sign in to comment.