Sonataadminbundle: to_string_callback is now String format only in 3.28

Created on 2 Dec 2017  路  7Comments  路  Source: sonata-project/SonataAdminBundle

I'm rendering a custom twig template within sonata_type_model_autocomplete
Works perfectly fine in
"sonata-project/admin-bundle": "3.27"

    $formMapper
        ->add('example_type', 'sonata_type_model_autocomplete', array(
                'container_css_class'   => 'select2-image',
                'class'                 => 'AppBundle:ExampleType',
                'to_string_callback'    => function($entity, $property) use ($engine) {
                    return $engine->render(
                        'AppBundle:ExampleTypeAdmin:autocomplete_example_type.html.twig',
                        ['example' => $entity]
                    );
                },
        ))
    ;

"sonata-project/admin-bundle": "3.28"
Latest admin bundle renders the selection as "string", is there a new way to render it HTML RAW?

select2 autocomplete issue

Most helpful comment

As workaround you can extend the template and override sonata_type_model_autocomplete_dropdown_item_format and sonata_type_model_autocomplete_selection_format blocks.
New option like is_safe in Twig will be great.

All 7 comments

Sorry, but we try to keep github issues for feature requests and bugs only.

Can you please name the PR which broke the BC?

The only thing that could effect the Select2 is this PR.

https://github.com/sonata-project/SonataAdminBundle/pull/4796/files

Just tested this using my project and wanted to confirm this PR #4796 prevent passing HTML through label, there is currently no bypass available. By preventing HTML passthrough you would not be able to take advantage of template in Select2 drop-down option select2
@ossinkine

Maybe you could provide a PR where you can pass a new option to force html rendering.

HTML should be disabled in default for security reasons.

As workaround you can extend the template and override sonata_type_model_autocomplete_dropdown_item_format and sonata_type_model_autocomplete_selection_format blocks.
New option like is_safe in Twig will be great.

Was this page helpful?
0 / 5 - 0 ratings