znalazłem świetny kawałek kodu w /vendor/sonata-project/admin-bundle/Sonata/AdminBundle/Form/Extension/Field/Type/FormTypeFieldExtension.php
które faktycznie tworzy tablicę typów dołączyć do widoku formularza, który używa do priorytetów bloku gałązka rendering: (linie 99 do 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);
Dlatego wszystko, co musiałem zrobić, to określić blok o nazwie mycompany_admin_content_galleries_sonata_type_collection_widget
lub mycompany_admin_content_galleries_slides_sonata_type_collection_widget
i ma zastosowanie tylko do tej formy admina :)
aby wykonać to rozwiązanie w mojej klasie Admin i dodało ten funk n:
public function getFormTheme()
{
return array_merge(
parent::getFormTheme(),
array('MyBundle:Gallery:admin.slides.html.twig')
);
}
i stworzyłem MyBundle/Resources/views/Gallery/admin.slides.html.twig
, zawierające następujące informacje:
{% 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 %}
Wystarczy wypełniając swoją odpowiedź, możesz zarejestrować swoje pliki szablonów z gałązką więc nie trzeba scalić termin w admin class z "getFormTheme()", zobacz: http://symfony.com/doc/current/cookbook/form/create_custom_field_type.html#creating-a-template-for-the-field – Cassiano
Tam wspomniano "aby zdefiniować czarny nazywa się ... "taki sam jak ostatni krok, w którym tworzysz blok w pliku admin.slides.html.twig ?? Lub gdzie definiujesz ten blok? – Mentos93