SyliusCmsPlugin
SyliusCmsPlugin copied to clipboard
Extends your entities?
Hello, I'm using your "CMS plugin for Sylius applications" and I would like to extends your "Block" entity to add some properties (like displaying dates).
In Block.orm.yml file I see "BitBag\SyliusCmsPlugin\Entity\Block" has the type: mappedSuperclass
So I imagine I can extends it on my own project entity and add an TypeExtension but how?
I tried to define my class like this:
namespace App\Entity;
use App\Repository\BlockRepository;
use BitBag\SyliusCmsPlugin\Entity\Block as BaseBlock;
use Doctrine\ORM\Mapping\MappedSuperclass;
use Doctrine\ORM\Mapping\Table;
/**
* @MappedSuperclass
* @Table(name="bitbag_cms_block")
*/
class Block extends BaseBlock
{
/*
* ORM\Column(type="boolean")
*/
private $test;
public function isTest(): ?bool
{
return $this->test;
}
public function setTest(bool $test): self
{
$this->test = $test;
return $this;
}
}
and define this in yml:
sylius_resource:
resources:
bitbag_sylius_cms_plugin.block:
classes:
model: App\Entity\Block
but it doesn't work :-/
How can achieve to add other fields on your entities? Can you please help me on this?
Thanks by Advance. Yannick Lepetit
Hello, anybody can help me on this? Any idea?!
Hi!
I've done that for Section entity.
In your Block entity, you used @MappedSuperclass
annotation, but you should use @ORM\Entity
or @Entity
instead.
If it still doesn't work, you can override BlockTranslation
and BlockRepository
too.
For type extension, don't forget to override form's template, located at vendor/bitbag/cms-plugin/src/Resources/views/Block/Crud/_form.html.twig
Any news on this?
I am also trying to override the BlockType but its not working
sylius_resource: resources: bitbag_sylius_cms_plugin.block: driver: doctrine/orm classes: model: BitBag\SyliusCmsPlugin\Entity\Block interface: BitBag\SyliusCmsPlugin\Entity\BlockInterface repository: BitBag\SyliusCmsPlugin\Repository\BlockRepository controller: BitBag\SyliusCmsPlugin\Controller\BlockController translation: classes: model: BitBag\SyliusCmsPlugin\Entity\BlockTranslation interface: BitBag\SyliusCmsPlugin\Entity\BlockTranslationInterface
I have already create new BlockType, But when I added this entry form: App\Form\Block\Type\BlockType I got following error
Too few arguments to function Sylius\Bundle\ResourceBundle\Form\Type\AbstractResourceType::__construct(), 0 passed in var/cache/dev/ContainerPIiNQ66/getBlockTypeService.php on line 25 and at least 1 expected
I achieved it by adding my own patches using this: https://packagist.org/packages/cweagans/composer-patches
@yanlep The way you extended the Block entity is good (apart from MappedSuperclass), did you override form's template as @pierre-vassoilles mentioned?