Skip to content

Instantly share code, notes, and snippets.

@rande
Created August 2, 2011 10:31
Show Gist options
  • Save rande/1119984 to your computer and use it in GitHub Desktop.
Save rande/1119984 to your computer and use it in GitHub Desktop.
Simulate Association and Reuse Admin code
<?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