I'm trying to extend the SymfonyContentBundle StaticContent class. I've been looking at issue #5301 but I can not make it succeed.
What I have right now is:
# src/AppBundle/Document/StaticContent.php
<?php
namespace AppBundle\Document;
use Sylius\Component\Resource\Model\ResourceInterface;
use Sylius\Bundle\ContentBundle\Document\StaticContent as SyliusStaticContent;
class StaticContent extends SyliusStaticContent implements ResourceInterface
{
public function testMethod() {
return "this is my test method";
}
}
# app/config.yml
sylius_content:
driver: doctrine/phpcr-odm
resources:
static_content:
classes:
model: AppBundle\Document\StaticContent
# src/AppBundle/Resources/config/doctrine/StaticContent.phpcr.xml
<?xml version="1.0" encoding="UTF-8" ?>
<doctrine-mapping
xmlns="http://doctrine-project.org/schemas/phpcr-odm/phpcr-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/phpcr-odm/phpcr-mapping
https://github.com/doctrine/phpcr-odm/raw/master/doctrine-phpcr-odm-mapping.xsd"
>
<document name="AppBundle\Document\StaticContent" />
</doctrine-mapping>
Unfortunately, when I load a StaticContent object, it is now from my extended class:
$ php app/console psysh
Psy Shell v0.7.2 (PHP 5.6.25-2+deb.sury.org~xenial+1 — cli) by Justin Hileman
>>> $dm = $container->get("doctrine_phpcr.odm.default_document_manager")
=> Doctrine\ODM\PHPCR\DocumentManager {#14005
+"valueConverter": PHPCR\Util\ValueConverter {#12219},
}
>>> $page = $dm->find(null, "/cms/pages/pagina-de-prueba")
=> Sylius\Bundle\ContentBundle\Document\StaticContent {#11420}
Am I missing something?
Turns out that for existing content the class is stored as a property:
<property sv:name="phpcr:class" sv:type="String" sv:multi-valued="0">
<value length="32">
Symfony\Cmf\Bundle\ContentBundle\Model\StaticContentBase
</value>
</property>
So I had to execute a class migration to update the class for existing contents.
php app/console doctrine:phpcr:document:migrate-class "Sylius\Bundle\ContentBundle\Document\StaticContent" "AppBundle\Document\StaticContent"
New contents are being created with my new class without problem.
@belaustegui Sylius uses Stackoverflow as its official support channel. For future support questions please post these at http://stackoverflow.com/questions/tagged/sylius, tag your questions with sylius.
Thank you very much @steffenbrem! And sorry for the inconvenience.
Most helpful comment
@belaustegui Sylius uses Stackoverflow as its official support channel. For future support questions please post these at http://stackoverflow.com/questions/tagged/sylius, tag your questions with
sylius.