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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Anonymous’s picture

Almare created an issue. See original summary.

markhalliwell’s picture

Title: Ajax not working for dropbuttons (operation links) » Ajax not working in dropbuttons (operation links)
Version: 8.x-3.0-beta3 » 8.x-3.x-dev
Component: User interface » Templates
Priority: Major » Normal
Issue tags: -ajax modal, -Ajax
markhalliwell’s picture

Status: Active » Postponed (maintainer needs more info)
Related issues: +#2657124: Unable to publish nodes while using Bootstrap theme to create/edit

Please see if the commit in this related issue may have fixed this one too.

Anonymous’s picture

Status: Postponed (maintainer needs more info) » Active

No, 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.

markhalliwell’s picture

Status: Active » Postponed (maintainer needs more info)

No, 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.

codexmas’s picture

This 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.

markhalliwell’s picture

Status: Postponed (maintainer needs more info) » Closed (duplicate)
Related issues: +#2750443: Destination query parameter goes missing when dropdown button is rendered

Agreed. This looks like a duplicate of a core issue.

alexdmccabe’s picture

Status: Closed (duplicate) » Needs review
FileSize
589 bytes

The 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.

markhalliwell’s picture

Status: Needs review » Fixed
dpi’s picture

Status: Fixed » Needs work

Is this version targeted to >=php7.0?

Commit/patch uses null coalescing operator.

markhalliwell’s picture

Status: Needs work » Fixed
FileSize
1.11 KB

Ah, yep... you're right. I forget my local is 7.1 sometimes, my bad.

  • markcarver committed 964ab6a on 8.x-3.x
    Issue #2686247 by alexdmccabe, markcarver: Ajax not working in...
alexdmccabe’s picture

Status: Fixed » Needs review
FileSize
809 bytes

Oh, good catch on the PHP 7 thing. I forgot about that, too.

I tested the patch from #12 and I get a syntax error:

ParseError: syntax error, unexpected ',' in Composer\Autoload\includeFile() (line 73 of themes/contrib/bootstrap/src/Plugin/Preprocess/BootstrapDropdown.php).

Adding a new patch that resolves it.

markhalliwell’s picture

Status: Needs review » Fixed

Wow... I totally missed that.... bad day for typos lol Thanks!

alexdmccabe’s picture

It does concern me some that the syntax error wasn't caught by automated tests. Does the theme not have any?

markhalliwell’s picture

Themes cannot be tested via d.o so no, there's currently no tests. See #2769599: [PP-1] Allow themes to be testable.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.