Embedded admin template - symfony

I'd like to drastically customise the layout for one particular embedded admin. My block sits like so:
->add('options', CollectionType::class, [
'by_reference' => false,
'label' => false,
], [
'edit' => 'inline',
'inline' => 'table',
])
On the admin block within the .yaml I've tried adding a calls then set template and I've had no luck.
I've also tried:
[
'edit' => 'inline',
'inline' => 'table',
'template' => 'admin/example/example.html.twig'
]
Finally, I also tried within my OptionAdmin using the method setFormTheme().
Any help or suggestions would be much appreciated.

Related

Override oneToMany Template in Symfony and Sonata Admin

I have an entity Post which has many Comments and I have included as follows in my PostAdmin.php
->tab('Comments')
->with('')
->add('comments', 'sonata_type_collection', array('by_reference' => false,'disabled' => false, 'label' => ' ', 'required' => false,
'type_options' => array(
'delete' => false,
'btn_add' => false
)
), array(
'edit' => 'inline',
))
->end()
->end();
I have already customised edit.html.twig to include javascripts that run some functions which are unrelated to this question.
I would like to override the comments block in edit.html.twig to include some ajax functionality for buttons that would then publish, delete or edit a single comment from all the listed comments under the article.
How would I go about this?

Translations are not saved correctly using A2lix Translation + KnpLabs DoctrineBehaviors

In my Symfony project I use SonataAdminBundle and A2lixTranslationForm + KnpLabsDoctrineBehaviors bundles for multi-language support.
I have Serial and Episode entities which use standard OneToMany and ManyToOne relationship. I display episodes using sonata_type_collection:
->add('episodes', 'sonata_type_collection', [
'by_reference' => false,
],
[
'edit' => 'inline',
'inline' => 'table',
]
)
By default A2lixTranslation bundle displays translatable fields under each other. However, I need to display each translation field of the episode in its own column. In order to achieve this, I created three virtual fields with the same property_path:
->add('episode_title', 'a2lix_translations', [
'property_path' => 'translations',
'fields' => [
'title' => [
'attr' => [
'pattern' => false,
],
'label' => false,
],
],
'exclude_fields' => ['subTitle', 'description'],
'label' => 'Title',
])
->add('episode_subtitle', 'a2lix_translations', [
'property_path' => 'translations',
'fields' => [
'subTitle' => [
'label' => false,
],
],
'exclude_fields' => ['title', 'description'],
'label' => 'Subtitle',
'required' => false,
])
->add('episode_description', 'a2lix_translations', [
'property_path' => 'translations',
'fields' => [
'description' => [
'field_type' => 'textarea',
'label' => false,
],
],
'exclude_fields' => ['title', 'subTitle'],
'label' => 'Description',
'required' => false,
])
As you can see, I display only one field in each a2lix_translations form.
But I faced the following problem: only the last field value (description in this case) is saved when I add new episode using Add new button of the collection form and then clicking Update button of the parent (Serial) form. Wherein already existing episodes are saved correctly if edited.
Could you please point me why is this happening and how to fix the issue. I suppose each translations form values rewrite the previous ones, but why do this work normally when saving existing records?
Or maybe there is another way to display each field in the own column in sonata collection form, this also will be helpful.
Thank you.

Symfony2 - Drop down with the possibility of adding fields

Sorry for my english.
I need to create a drop down list (select option) with values ​​taken from an Entity.
I must also add options (I use select2 to do this).
When I send the form it doesn't work. How can I configure the field type to make it work?
I need the possibilities to adding multiple persons
My current code is
...
->add('person', 'entity', array(
'attr' => array(
'class' => 'tags'
),
'class' => 'AppBundle:Person',
'data_class' => null,
'label' => 'Persons',
'mapped' => false,
'multiple' => true,
'required' => false
));
Select2
$('select.tags').select2({
language: 'it',
tags: true,
tokenSeparators: [','],
width: '100%'
});
Error message
The offset "0" does not exist.

Sonata Admin - A2LiX Translation Field + Sonata Formatter Type

I've plugged Formatter (with CKeditor) to the 'content' field in one of my Sonata's Admin classes. This 'content' also has a translation, that's editable through 'a2lix_translations_gedmo' translations type. I've been trying to add CKeditor to this field as well, but it throws exceptions in any configuration I'm trying to set.
Google knows nothing about it, as well as SO. I've also looked in Sonata News Bundle sources (where sonata_formatter_type is implemented), but there are no translations available.
My Formatter field:
->add('content', 'sonata_formatter_type', [
'label' => "Content",
'event_dispatcher' => $formMapper->getFormBuilder()->getEventDispatcher(),
'format_field' => 'contentFormatter',
'source_field' => 'rawContent',
'ckeditor_context' => 'my_config',
'source_field_options' => [
'attr' => [
'class' => 'span10', 'rows' => 10
]
],
'listener' => TRUE,
'target_field' => 'content'
])
My Translation fields:
->add('translations', 'a2lix_translations_gedmo', [
'label' => "Управление локализациями",
'translatable_class' => 'AppBundle\Entity\Article',
'fields' => [
'content' => [
'locale_options' => [
'ru' => [
'label' => 'Контент'
]
]
]
]
])
Maybe someone knows how to add 'sonata_formatter_type' to this damn 'a2lix_translations_gedmo' type (or 'a2lix_translations')?
'a2lix_translations_gedmo' or 'a2lix_translations' depends of the translation strategy chosen.
Gedmo strategy is discouraged and you shoud use a more recent translation strategy like the KnpLabs that I recommend. https://github.com/KnpLabs/DoctrineBehaviors#translatable
Othewise, see https://github.com/a2lix/TranslationFormBundle/issues/177#issuecomment-94949480

How to add two sonata_type_collection fields of the same property in the same admin?

Suppose you have ArticleAdmin and CommentsAdmin. It is easy to add one-to-many editing in Sonata:
$formMapper->add('comments', 'sonata_type_collection',
array(
'by_reference' => false,
),
array(
'edit' => 'inline',
'inline' => 'table',
)
);
However, suppose I have more complicated CommentsAdmin form and it can has two visualizations depending on the kind of comment in it. I would like to display two sonata_type_collection fields in ArticleAdmin for grouping different types of comments into two different edit tables.
Adding another add('comments', ...) is of course incorrect, and adding add('comments2', ...) results in exception.
I will manage separating comments between two fields in admin, but how to create sonata_type_collection field on a virtual entity field Article::comments2? How to tell Sonata Admin what kind of collection should it be?
I'm not sure if this will help you but:
->add('categoryHasMedia', 'sonata_type_collection', array(
'cascade_validation' => true,
'label' => 'Logo\'s'
), array(
'edit' => 'inline',
'inline' => 'table',
'link_parameters' => array('context' => $context),
'admin_code' => 'appstrakt.project.admin.category_has_media',
))
By using admin_code you can tell which admin class you want to use for that sonata_type_collection if I'm not mistaken.

Resources