Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I tried to get a ajax modal window from a dropdown link aka operations link. Bootstap renders those links as button instead of leaving them links. This makes it now impossible to create a ajax request. This behavior is destructive for all changes to operations link with a boostrap them. I try to investigate the nessesary changes to solve this. Any advices are welcome to fix this issue.
My code sample from my AccountListBuilder.php to create the operation link:
$operations['cancel'] = array(
'title' => $this->t('Cancel account'),
'weight' => 0,
'url' => $entity->toUrl('cancel'),
'attributes' => array(
'class' => array('use-ajax'),
'data-dialog-type' => 'dialog',
'data-dialog-options' => Json::encode(array(
'width' => 1200,
'height' => 500,
))
),
);
In the admin backend the link work as expected in bootstrap not.
Comment | File | Size | Author |
---|---|---|---|
#14 | bootstrap-ajax_operations-2686247-14.patch | 809 bytes | alexdmccabe |
#12 | ajax_not_working_in-2686247-12.patch | 1.11 KB | markhalliwell |
#8 | bootstrap-ajax_operations-2686247-8.patch | 589 bytes | alexdmccabe |
Comments
Comment #1
Anonymous (not verified) CreditAttribution: Anonymous commentedAlmare created an issue. See original summary.
Comment #2
markhalliwellComment #3
markhalliwellPlease see if the commit in this related issue may have fixed this one too.
Comment #4
Anonymous (not verified) CreditAttribution: Anonymous commentedNo, it still doesn't work. I think this is caused by the complete different handling of the dropdown. Originally the buttons were links, but unfortunately bootstrap changes these to buttons and handles the implementation via javascript. If bootstrap doesn't switch back to links it should implement the correct handling in the javascript and add the additional data informations like data-dialog-type and data-dialog-options to the buttons.
Comment #5
markhalliwellNo, it doesn't change them all to buttons, just the first one (as just a split button at that). The way I setup the code to work is so that it proxies the events to the original element (or at least that's how I thought I set it up).
The Bootstrap dropdown component itself requires links inside the list
<li>
element for it to be styled properly.I need a better explanation (and patch) to understand exactly what it is you're trying to accomplish if it's truly a bug. Also, the example given in the issue summary is incomplete. A full working (code wise) example of the theme hooks being invoked would be greatly appreciated.
Comment #6
codexmas CreditAttribution: codexmas at Acquia commentedThis is very likely the same issue as this
All of your extra attributes are being destroyed, and it happens to all of the operations, not just the toggle/top most link.
Comment #7
markhalliwellAgreed. This looks like a duplicate of a core issue.
Comment #8
alexdmccabeThe other issue was not a core issue, and did not fix AJAX in operations links.
Attached is a patch that solved the problem for me.
Comment #10
markhalliwellComment #11
dpiIs this version targeted to >=php7.0?
Commit/patch uses null coalescing operator.
Comment #12
markhalliwellAh, yep... you're right. I forget my local is 7.1 sometimes, my bad.
Comment #14
alexdmccabeOh, good catch on the PHP 7 thing. I forgot about that, too.
I tested the patch from #12 and I get a syntax error:
Adding a new patch that resolves it.
Comment #16
markhalliwellWow... I totally missed that.... bad day for typos lol Thanks!
Comment #17
alexdmccabeIt does concern me some that the syntax error wasn't caught by automated tests. Does the theme not have any?
Comment #18
markhalliwellThemes cannot be tested via d.o so no, there's currently no tests. See #2769599: [PP-1] Allow themes to be testable.