Search code examples
symfonysymfony-cmfdoctrine-phpcr

How to extend the Page class from Symfony simple cms bundle?


I'm trying to extend the default Page class from symfony simple cms bundle.

The problem:
The custom property is not persisted.

Below is the code of the class which extends from BasePage.

use Doctrine\ODM\PHPCR\Mapping\Annotations\Document;
use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM;
use Symfony\Cmf\Bundle\SimpleCmsBundle\Doctrine\Phpcr\Page as BasePage;

/**
 * {@inheritDoc}
 * @PHPCRODM\Document(referenceable=true)
 */
class Product extends BasePage
{
    public $node;

    /**
     * @var string(nullable=true)
     */
    private $code;

   /**
    * Get Code
    * @return string
    */
    public function getCode()
    {
        return $this->code; 
    }

   /**
    * Set code
    * @return Product
    */
    public function setCode($code)
    {
        $this->code = $code;
        return $this;
    } 
}   

Solution

  • This looks almost correct, but you miss a mapping on the $code:

    /**
     * @PHPCRODM\String(nullable=true)
     */
    private $code;
    

    I assume that $code is not language dependant. Otherwise you would need nullable=true,translatable=true

    If you also want to have the PHPCR node mapped, you need

    /**
     * @PHPCRODM\Node
     */
    public $node;