我发现了大量代码,/vendor/sonata-project/admin-bundle/Sonata/AdminBundle/Form/Extension/Field/Type/FormTypeFieldExtension.php
其中实际上设置了一个类型数组以附加到表单视图,它用于优先处理树枝块渲染:(第 99 到 105 行)
// add a new block types, so the Admin Form element can be tweaked based on the admin code
$types = $view->getVar('types');
$baseName = str_replace('.', '_', $sonataAdmin['field_description']->getAdmin()->getCode());
$baseType = $types[count($types) - 1];
$types[] = sprintf('%s_%s', $baseName, $baseType);
$types[] = sprintf('%s_%s_%s', $baseName, $sonataAdmin['field_description']->getName(), $baseType);
因此,我所要做的就是定义一个名为mycompany_admin_content_galleries_sonata_type_collection_widget
or的块mycompany_admin_content_galleries_slides_sonata_type_collection_widget
,它只适用于这个管理表单:)
为了在我的管理类中完成这个解决方案,我添加了这个函数:
public function getFormTheme()
{
return array_merge(
parent::getFormTheme(),
array('MyBundle:Gallery:admin.slides.html.twig')
);
}
我创建了MyBundle/Resources/views/Gallery/admin.slides.html.twig
,包含以下内容:
{% use 'SonataAdminBundle:Form:form_admin_fields.html.twig' %} // I think this
line is not really needed as the base admin's form theme uses this file
{% block my_bundle_content_pages_slides_sonata_type_collection_widget %}
// copied and edited the contents of Sonata/DoctrineORMAdminBundle/Resources/views/CRUD/edit_orm_one_to_many.html.twig
{% endblock %}