Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extends your entities? #425

Closed
yanlep opened this issue Mar 9, 2022 · 5 comments
Closed

Extends your entities? #425

yanlep opened this issue Mar 9, 2022 · 5 comments

Comments

@yanlep
Copy link

yanlep commented Mar 9, 2022

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

@yanlep
Copy link
Author

yanlep commented Mar 18, 2022

Hello, anybody can help me on this? Any idea?!

@pierre-vassoilles
Copy link

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

@patildipakr
Copy link

patildipakr commented May 30, 2022

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

@yanlep
Copy link
Author

yanlep commented May 30, 2022

I achieved it by adding my own patches using this: https://packagist.org/packages/cweagans/composer-patches

@pbalcerzak
Copy link
Contributor

pbalcerzak commented Oct 4, 2022

@yanlep The way you extended the Block entity is good (apart from MappedSuperclass), did you override form's template as @pierre-vassoilles mentioned?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants