I have this method in AssignmentTypeAdmin:
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->add('code', 'text')
->add('label', 'text', array('label'=>'Libellé'))
->add('assignHierarchyNode.label', 'text', array('label' => 'Noeud hiérarchique'))
->add('assignPortfolioType.portfolioTypeLabel', null, array('label' => 'Type de portefeuille'))
->add('assignGeoHierarchyNodeType.label', null, array('label' => 'Type de noeud hiérarchique'));
}
In AssignmentType class:
/**
* @ORM\ManyToOne(targetEntity="HierarchyManagerBundle\Entity\HierarchyNode")
* @ORM\JoinColumn(name="assign_hierarchy_node_id", referencedColumnName="id", nullable=FALSE)
*/
private $assignHierarchyNode;
In HierarchyNode class: ...
/**
* @var string
* @Gedmo\TreePathSource
* @ORM\Column(name="label", type="string", length=255)
*/
private $label;
... also get and set methods.
My problem is I get this error and I don't have any idea why:
PropertyAccessor requires a graph of objects or arrays to operate on, but it found type "NULL" while trying to traverse path "assignHierarchyNode.label" at property "label".
I use Symfony 3.1, Doctrine 2.5.2, Sonata Bundle for this. Thank you in advance!
Just have a look there : Sonata PostPersist
Here you can find a Sonata constructor, it may help you. It can be better than using a _constructor. You can find just bellow an exemple.
public function postPersist($client)
{
$em = $this->getConfigurationPool()->getContainer()->get('doctrine.orm.entity_manager');
if ($client instanceof Client )
{
$test = new Test();
$test->setClient($client);
$test->setSurname($client->getSurname());
$test->setFirstname($client->getFirstname());
$em->persist($test);
$em->flush();
}
}
Hope it was usefull. If you have any question just ask.