索纳塔管理软件包 - 表格类型:sonata_type_collection - 自定义模板?

问题描述:

是否有可能来覆盖表单类型的模板:“sonata_type_collection”?索纳塔管理软件包 - 表格类型:sonata_type_collection - 自定义模板?

伊夫沿着这些路线的尝试:

$formMapper->add('slides', 'sonata_type_collection', array(), array(
       'edit' => 'inline', 
       'inline' => 'table', 
       'sortable' => 'priority', 
       'template' => 'MyBundle:Form:slides.admin.html.twig' 
      )); 

,但无济于事。

我知道我可以覆盖整个模板,但我只想做这种形式,并不是所有的地方我用这种形式类型的地方。

有谁知道这是可能的吗?

由于

我发现的代码很大位/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_widgetmycompany_admin_content_galleries_slides_sonata_type_collection_widget块,它仅适用于本管理形式:)

要完成自己的管理类这种解决方案我加入这个函数的N:

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 %} 
+0

刚刚完成你的答案,你可以用树枝注册您的模板文件,因此你不需要在管理合并术语与“getFormTheme()”类,请参阅:http://symfony.com/doc/current/cookbook/form/create_custom_field_type.html#creating-a-template-for-the-field – Cassiano 2014-08-04 14:20:34

+0

还有,你提到的“定义黑色的叫......”一样,你创建admin.slides.html.twig块中的最后一步?或者你在哪里定义该块? – Mentos93 2016-08-17 13:28:52