Skip to content

Commit

Permalink
OP-321: Init update block functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
jkindly committed Jun 21, 2024
1 parent 3bd1854 commit ee7a3e4
Show file tree
Hide file tree
Showing 26 changed files with 453 additions and 114 deletions.
19 changes: 8 additions & 11 deletions src/Entity/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class Block implements BlockInterface
use ProductsAwareTrait;
use TaxonAwareTrait;
use ChannelsAwareTrait;
use BlockContentAwareTrait;
use TranslatableTrait {
__construct as protected initializeTranslationsCollection;
}
Expand All @@ -32,13 +33,14 @@ public function __construct()
$this->initializeProductsCollection();
$this->initializeTaxonCollection();
$this->initializeChannelsCollection();
$this->initializeContentsCollection();
}

/** @var int|null */
protected $id;
protected ?int $id;

/** @var string|null */
protected $code;
protected ?string $code;

protected ?string $name;

public function getId(): ?int
{
Expand All @@ -57,17 +59,12 @@ public function setCode(?string $code): void

public function getName(): ?string
{
/** @var BlockTranslationInterface $blockTranslationInterface */
$blockTranslationInterface = $this->getBlockTranslation();

return $blockTranslationInterface->getName();
return $this->name;
}

public function setName(?string $name): void
{
/** @var BlockTranslationInterface $blockTranslationInterface */
$blockTranslationInterface = $this->getBlockTranslation();
$blockTranslationInterface->setName($name);
$this->name = $name;
}

public function getContent(): ?string
Expand Down
57 changes: 57 additions & 0 deletions src/Entity/BlockContent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?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\Entity;

final class BlockContent implements BlockContentInterface
{
protected ?int $id;

protected ?string $type;

protected array $configuration = [];

protected ?BlockInterface $block;

public function getId(): ?int
{
return $this->id;
}

public function getType(): ?string
{
return $this->type;
}

public function setType(?string $type): void
{
$this->type = $type;
}

public function getConfiguration(): array
{
return $this->configuration;
}

public function setConfiguration(array $configuration): void
{
$this->configuration = $configuration;
}

public function getBlock(): ?BlockInterface
{
return $this->block;
}

public function setBlock(?BlockInterface $block): void
{
$this->block = $block;
}
}
26 changes: 26 additions & 0 deletions src/Entity/BlockContentAwareInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?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\Entity;

use Doctrine\Common\Collections\Collection;

interface BlockContentAwareInterface
{
public function initializeContentsCollection(): void;

public function getContents(): Collection;

public function hasContent(BlockContentInterface $contentItem): bool;

public function addContent(BlockContentInterface $contentItem): void;

public function removeContent(BlockContentInterface $contentItem): void;
}
48 changes: 48 additions & 0 deletions src/Entity/BlockContentAwareTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?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\Entity;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;

trait BlockContentAwareTrait
{
protected Collection $contents;

public function initializeContentsCollection(): void
{
$this->contents = new ArrayCollection();
}

public function getContents(): Collection
{
return $this->contents;
}

public function hasContent(BlockContentInterface $contentItem): bool
{
return $this->contents->contains($contentItem);
}

public function addContent(BlockContentInterface $contentItem): void
{
if (!$this->hasContent($contentItem)) {
$this->contents->add($contentItem);
}
}

public function removeContent(BlockContentInterface $contentItem): void
{
if ($this->hasContent($contentItem)) {
$this->contents->removeElement($contentItem);
}
}
}
30 changes: 30 additions & 0 deletions src/Entity/BlockContentInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?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\Entity;

use Sylius\Component\Resource\Model\ResourceInterface;

interface BlockContentInterface extends ResourceInterface
{
public function getId(): ?int;

public function getType(): ?string;

public function setType(?string $type): void;

public function getConfiguration(): array;

public function setConfiguration(array $configuration): void;

public function getBlock(): ?BlockInterface;

public function setBlock(?BlockInterface $block): void;
}
3 changes: 2 additions & 1 deletion src/Entity/BlockInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ interface BlockInterface extends
TaxonAwareInterface,
CollectionableInterface,
ChannelsAwareInterface,
ContentableInterface
ContentableInterface,
BlockContentAwareInterface
{
public function getCode(): ?string;

Expand Down
26 changes: 0 additions & 26 deletions src/Entity/BlockTranslation.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,9 @@ class BlockTranslation extends AbstractTranslation implements BlockTranslationIn
/** @var int */
protected $id;

/** @var string|null */
protected $name;

/** @var string|null */
protected $content;

/** @var string|null */
protected $link;

public function getName(): ?string
{
return $this->name;
}

public function setName(?string $name): void
{
$this->name = $name;
}

public function getContent(): ?string
{
return $this->content;
Expand All @@ -50,14 +34,4 @@ public function getId(): ?int
{
return $this->id;
}

public function getLink(): ?string
{
return $this->link;
}

public function setLink(?string $link): void
{
$this->link = $link;
}
}
8 changes: 0 additions & 8 deletions src/Entity/BlockTranslationInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,7 @@

interface BlockTranslationInterface extends ResourceInterface, TranslationInterface
{
public function getName(): ?string;

public function setName(?string $name): void;

public function getContent(): ?string;

public function setContent(?string $content): void;

public function getLink(): ?string;

public function setLink(?string $link): void;
}
32 changes: 32 additions & 0 deletions src/Form/Type/BlockContent/BlockContentTextConfigurationType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?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\Form\Type\BlockContent;

use BitBag\SyliusCmsPlugin\Form\Type\WysiwygType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\OptionsResolver\OptionsResolver;

final class BlockContentTextConfigurationType extends AbstractType
{
public const TYPE = 'content_text';

public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'label' => 'bitbag_sylius_cms_plugin.ui.text',
]);
}

public function getParent(): string
{
return WysiwygType::class;
}
}
Loading

0 comments on commit ee7a3e4

Please sign in to comment.