问题
I am using Sonata Admin to manage CRUD tasks in my application. In one Admin called Multimedia, which has one-to-many relations with Files and Weblinks, both of which are embedded in the Multimedia form. I have a custom template that renders the fields horizontally and with titles. My question is, do I have to specify two different templates for Files and Weblinks because using a single file has failed, Files renders the embed form how I want it but weblink ignores directive.
Here's the Admin Code
class MultimediaAdmin extends Admin
{
// Fields to be shown on create/edit forms
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->with('General')
->add('name')
->add('publish_date')
->add('keywords')
->add('copyright')
->end()
->with('Files')
->add('files','sonata_type_collection',
array('label' => 'Multimedia Files',
'btn_add' => 'Add File',
'by_reference' => 'false',
'type_options' => array('delete' => false)
), array(
'edit' => 'inline',
'template' => 'MyMultimediaBundle:Multimedia:horizontal.fields.html.twig'
)
)
->end()
->with('Tags')
->add('tags')
->end()
->with('Weblinks')
->add('weblinks','sonata_type_collection',
array('label' => 'External Videos',
'btn_add' => 'Add Video',
'by_reference' => 'false',
'type_options' => array('delete' => false)
), array(
'edit' => 'inline',
'template' => 'MyMultimediaBundle:Multimedia:horizontal.fields.html.twig'
)
)
->end()
;
}
// Fields to be shown on lists
protected function configureListFields(ListMapper $listMapper)
{
$listMapper
->addIdentifier('name')
->add('publish_date')
->add('keywords')
->add('copyright')
->add('_action','actions',array('actions'=>(array('edit'=>array(),'view'=>array(),'delete'=>array()))))
;
}
// Fields to be shown on filter forms
protected function configureDatagridFilters(DatagridMapper $datagridMapper)
{
$datagridMapper
->add('name')
->add('publish_date')
->add('keywords')
->add('copyright')
;
}
public function prePersist($multimedia)
{
$this->preUpdate($multimedia);
}
public function preUpdate($multimedia)
{
$multimedia->setFiles($multimedia->getFiles());
}
public function getFormTheme()
{
return array_merge(
parent::getFormTheme(),
array('MyMultimediaBundle:Multimedia:horizontal.fields.html.twig')
);
}
回答1:
I figured it out, pretty basic error in the template regarding block naming. Hope this helps someone in future
来源:https://stackoverflow.com/questions/19873566/custom-template-in-sonata-admin