0

I've a problem in my form for the entity Page from simplecms I want to add an item in the array Extras, so i added it in my formtype :

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Cmf\Bundle\SimpleCmsBundle\Doctrine\Phpcr\Page;

class PageType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->add('title', 'text', array(
                'label' => 'Titre',
                'attr' => array('placeholder' => 'Titre complet de la page')
            ))
        ->add('name', 'text', array(
            'label' => 'Label',
            'attr' => array('placeholder' => 'nom-simplifie-de-la-page')
            ))
        ->add('body', 'ckeditor')
        ->add('locale', 'hidden')
        ->add('publishable')
            ->add('extras_link','text', array(
                'property_path' =>"extras['link']",
            ));                        
}

The vars are in class Page (i didnt had to override it) and functions removeExtra() and addExtra() too (necessary to my form alimentation)

/**
 * Add a single key - value pair to extras
 *
 * @param string $key 
 * @param string $value - if this is not a string it is cast to one
 */
public function addExtra($key, $value)
{
    $this->extras[$key] = (string) $value;
}

/**
 * Remove a single key - value pair from extras, if it was set.
 *
 * @param string $key
 */
public function removeExtra($key)
{
    if (array_key_exists($key, $this->extras)) {
        unset($this->extras[$key]);
    }
}

form is working, but when i submit, it find removeExtra() but not addExtra()

"Found the public method "removeExtra()", but did not find a public "addExtra()" on class Symfony\Cmf\Bundle\SimpleCmsBundle\Doctrine\Phpcr\Page"

Somebody already had this problem? or know how to add data in extras? THX (sorry for my english)

1 Answers1

1

This is a limitation of the form layer unfortunately. The logic that looks for the right method only finds a adder with one parameter. What we ended up doing is using the burgov/key-value-form-bundle : https://github.com/Burgov/KeyValueFormBundle/

This required a PR like this to enabled in SeoBundle: https://github.com/symfony-cmf/SeoBundle/pull/158

from the code in Page::setExtras i think this should already work, though a similar PR to the one on SeoBundle would make it slightly more efficient.

dbu
  • 1,497
  • 9
  • 8