/** * @param \Sonata\AdminBundle\Form\FormMapper $formMapper * * @return \Symfony\Component\Form\FormBuilder */ protected function getBlockBuilder(FormMapper $formMapper) { // simulate an association ... $fieldDescription = $this->getSharedBlockAdmin()->getModelManager()->getNewFieldDescriptionInstance($this->sharedBlockAdmin->getClass(), 'block'); $fieldDescription->setAssociationAdmin($this->getSharedBlockAdmin()); $fieldDescription->setAdmin($formMapper->getAdmin()); $fieldDescription->setOption('edit', 'list'); $fieldDescription->setAssociationMapping(array('fieldName' => 'block', 'type' => \Doctrine\ORM\Mapping\ClassMetadataInfo::MANY_TO_ONE)); return $formMapper->create('blockId', 'sonata_type_model_list', array('sonata_field_description' => $fieldDescription, 'class' => $this->getSharedBlockAdmin()->getClass(), 'model_manager' => $this->getSharedBlockAdmin()->getModelManager(), 'label' => 'block', 'required' => false)); }
/** * {@inheritdoc} */ public function preUpdate($object) { parent::preUpdate($object); if ($object->getPage()) { $site = $object->getPage()->getSite(); $object->setSite($site); } $translations = $object->getTranslations(); foreach ($translations as $trans) { $trans->setObject($object); } // because of current locale's translation being overwritten with base object data if (isset($site)) { $locale = $site->getDefaultLocale(); if ($locale) { $object->setSettings($translations[$locale]->getSettings()); $object->setEnabled($translations[$locale]->getEnabled()); } } }