简体   繁体   中英

Sonata Admin - sonata_type_collection: select from the list of existing entities

I'm trying to implement many-to-many relationship between Page and Image entity using PageHasImage bridge entity. In the PageAdmin I added the field like so:

->add(
      'galleryImages', 
      'sonata_type_collection', 
      array(
            'cascade_validation' => false,
            'by_reference' => false,
            'type_options' => array('delete' => false)
           ),
      array(
            'edit' => 'inline',
            'inline' => 'table',
            'sortable' => 'position',
            'admin_code' => 'sonata.admin.page_has_image'
      )
 )

which gives me an option to add new Image field, and then either upload new image or select it from the list of uploaded ones. The upload part works as expected, but selecting from the already uploaded images list does nothing. The Select button in Images list has just '#' in its href and doesn't seem to do anything useful. There are also checkboxes next to listed images but no action buttons to make any use of the selection.

What should I configure to make the actions on the list mean anything? My guess is there's something missing in the setters of relationsships or in lifecycle event methods but I'd apprecieate some guidance.

Ok, I can see it's not a popular question but for any poor soul who comes across this issue soon - there there is a bug in Sonata. Also, I'd rate Sonata Admin documentation 4/10... I've spent a few days looking for a decent description of the various configuration parameters of sonata forms, being sure I have misconfigured something. Great way to spend your life, eh.

Here's the solution: https://github.com/sonata-project/SonataDoctrineORMAdminBundle/issues/404

I'll copy it here for completeness' sake:

Commenting the following lines in Resources/views/CRUD/edit_orm_many_association_script.html.twig fixes the issue

if (this.nodeName == 'A' && (target.attr('href').length == 0 ||     target.attr('href')[0] == '#')) {
Admin.log('[{{ id }}|field_dialog_form_list_link] element is an anchor, skipping action', this);
return;

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM