Adding related items using Sonata Admin and Propel
You could use the plain old collection
field type.
Given the following ImageType
:
class ImageType extends AbstractType{ public function buildForm(FormBuilderInterface $builder, array $options) { $builder->add('title', 'text'); $builder->add('description', 'textarea'); $builder->add('file', 'file', array('required' => false)); } public function getName() { return 'image'; }}
The PortfolioAdmin
class becomes:
class PortfolioAdmin extends Admin{ protected $baseRouteName = 'portfolio'; protected $baseRoutePattern = 'portfolio'; // Fields to be shown on create/edit forms protected function configureFormFields(FormMapper $formMapper) { $formMapper ->add('title', 'text', array('label' => 'Title')) ->add('images', 'collection', array( 'type' => new ImageType(), 'by_reference' => false, 'allow_add' => true, 'allow_delete' => true, )) ->add('description', 'text', array('label' => 'Description')) ; }}