I have a the Token Browsing UI added to a form as below:

$form['token_tree'] = [
      '#theme' => 'token_tree_link',
      '#token_types' => ['media'],
    ];

This works in Drupal 8.5. The form includes a link that says "Browse available tokens.", and when clicked, a modal window pops up with the tokens nested and clickable. However, when I use the same form in Drupal 8.6-rc1, the modal window pops up, but every term is on it's own line instead of nested beneath parent terms. Additionally, the text "Click a token to insert it into the last field you've clicked" appears at the top of the modal window, but none of the tokens are links. I think the jquery is broken somehow, but I'm not sure what broke between 8.5 and 8.6.

Also, when I navigate to the token help page in Drupal 8.6, the terms there are nested correctly. So something is different between the table on the help page, and the table in my form.

Has anybody else encountered this issue? Do I need to be using different code in my form?

Comments

rhealan created an issue. See original summary.

rebecca.healan@turner.com’s picture

dave reid’s picture

So the issue is that when the dialog is loaded, Drupal.behaviors.tokenTree.attach() is run and the HTML/context provided is at the root the table. Using jQuery('table', context) doesn't work when the root element is the thing you are wanting to find (as per http://danielnouri.org/notes/2011/03/14/a-jquery-find-that-also-finds-th...). Wrapping the table in a div allows this to work.

dave reid’s picture

Title: Token Browsing in form not collapsible in Drupal 8.6 » Token modal unusable with Drupal 8.6
dave reid’s picture

I can confirm that in Drupal 8.5 and below, dialog contents were wrapped in an extra div, but as of Drupal 8.6, they are not.

dave reid’s picture

Status: Active » Needs review
StatusFileSize
new971 bytes

This adds an extra wrapping div to the AJAX request and allows the JS selectors to work again. For Drupal <=8.5, this means that the token tree in a modal will have two wrapping divs, but I think that is acceptable for now.

dave reid’s picture

Fixed errant semicolon in docs.

berdir’s picture

Category: Support request » Bug report
Priority: Normal » Major
Status: Needs review » Fixed

Thanks Dave, that's not very pretty but fixes the problem for now, we'll see what will happen in #3001570: Drupal.attachBehaviors() documents inconsistent instructions about the context parameter.

Committed for now. Will also do another release.

  • Berdir committed 7c0c8cd on 8.x-1.x authored by Dave Reid
    Issue #2994671 by Dave Reid, rhealan: Token modal unusable with Drupal 8...
berdir’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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