It seems as if it only checks if the Form implements the 
ObjectManagerAwareInterface and not for the elements.
Could it be because of the fact that the Elements are Strings representing 
Invokable Classes?

initializers' => array(
                'ObjectManagerInitializer' => function ($element, 
$formElements)
        {
            if ($element instanceof ObjectManagerAwareInterface)
            {
                $services = $formElements->
getServiceLocator();
                $entityManager = 
$services->get('Doctrine\ORM\EntityManager');

                $element->setObjectManager($entityManager);
            }
        },

It only check if the Element is an instanceof ObjectManagerAwareInterface.
I want it to do the same for my GenreFieldSet.


Op vrijdag 12 december 2014 17:42:19 UTC+1 schreef Antenne:
>
> I have the following setup:
>
> Module.php
>
> class Module implements ServiceProviderInterface, 
> FormElementProviderInterface
> {
> public function getFormElementConfig()
>     {
>         return array(
>             'invokables' => array(
>                 'GenreFieldSet' => 'Cms\Form\GenreFieldSet',
>             ),
>             'initializers' => array(
>                 'ObjectManagerInitializer' => function ($element, 
> $formElements)
>         {
>             if ($element instanceof ObjectManagerAwareInterface)
>             {
>                 $services = $formElements->getServiceLocator();
>                 $entityManager = 
> $services->get('Doctrine\ORM\EntityManager');
>
>                 $element->setObjectManager($entityManager);
>             }
>         },
>             ),
>         );
>     }
> }
>
> Controller:
>
> /**
>      * Method called to edit a Genre
>      * 
>      * @return ViewModel
>      */
>     public function editAction()
>     {
>         $formManager = 
> $this->getServiceLocator()->get('FormElementManager');
>         $form = $formManager->get('Cms\Form\GenreForm');
>       ...
>     }
>
> Form:
>
> class GenreForm extends Form
> {
>
>     public function init()
>     {
>         $this->add(array(
>             'name' => 'genre',
>             'type' => 'GenreFieldSet',
>         ));
>
>         $this->add(array(
>             'name' => 'submit',
>             'type' => 'Submit',
>             'attributes' => array(
>                 'value' => 'Go',
>                 'id' => 'submitbutton',
>             ),
>         ));
>     }
>
> }
>
> FieldSet:
>
> class GenreFieldSet extends Fieldset implements 
> ObjectManagerAwareInterface, InputFilterProviderInterface
> {
>     /**
>      * @var InputFilter
>      *
>      */
>     protected $inputFilter;
>
>     /**
>      * @var ObjectManager
>      *
>      */
>     protected $objectManager;
>
>     public function __construct()
>     {
>         $this->setHydrator(new 
> DoctrineEntity($this->getObjectManager()))->setObject(new Genre());
>
>         $this->addElements();
>     }
>
>     public function addElements()
>     {
>         ...
>     }
>
>     public function getInputFilterSpecification()
>     {
>        ...
>     }
>
>     /**
>      * Get objectManager
>      * 
>      * @return type 
>      */
>     public function getObjectManager()
>     {
>         return $this->objectManager;
>     }
>
>     /**
>      * Set objectManager
>      * 
>      * @param ObjectManager $objectManager
>      * @return \Cms\Services\AntenneService
>      */
>     public function setObjectManager(ObjectManager $objectManager)
>     {
>         $this->objectManager = $objectManager;
>
>         return $this;
>     }
>
> }
>
> I keep getting the following exception:
>
> ( ! ) Catchable fatal error: Argument 1 passed to 
> DoctrineModule\Stdlib\Hydrator\DoctrineObject::__construct() must be an 
> instance of Doctrine\Common\Persistence\ObjectManager, null given
>
> Meaning the intializer in the Module didn't set the ObjectManager properly.
> Does somebody know what to do?
>
> Thanks!!
>

-- 
You received this message because you are subscribed to the Google Groups 
"doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/doctrine-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to