Created
August 2, 2011 10:31
-
-
Save rande/1119984 to your computer and use it in GitHub Desktop.
Simulate Association and Reuse Admin code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// simulate an association ... | |
$fieldDescription = $formMapper->getAdmin()->getModelManager()->getNewFieldDescriptionInstance($this->mediaAdmin->getClass(), 'media' ); | |
$fieldDescription->setAssociationAdmin($this->getMediaAdmin()); | |
$fieldDescription->setAdmin($formMapper->getAdmin()); | |
$fieldDescription->setOption('edit', 'list'); | |
$fieldDescription->setAssociationMapping(array('fieldName' => 'media', 'type' => \Doctrine\ORM\Mapping\ClassMetadataInfo::MANY_TO_ONE)); | |
// create the builder | |
$builder = $formMapper->create('mediaId', 'sonata_type_model', array( | |
'sonata_field_description' => $fieldDescription, | |
'class' => $this->getMediaAdmin()->getClass(), | |
'model_manager' => $this->getMediaAdmin()->getModelManager() | |
)); | |
// use the builder | |
$formMapper->add('settings', 'sonata_type_immutable_array', array( | |
'keys' => array( | |
array('title', 'text', array('required' => false)), | |
array('context', 'choice', array('required' => true, 'choices' => $contextChoices)), | |
array('format', 'choice', array('required' => count($formatChoices) > 0, 'choices' => $formatChoices)), | |
array($builder, null, array()), | |
) | |
)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment