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?
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | 2994671-fix-ajax-missing-wrapper-86.patch | 970 bytes | dave reid |
| #2 | Screen Shot 2018-08-23 at 11.31.10 AM.png | 154 KB | rebecca.healan@turner.com |
Comments
Comment #2
rebecca.healan@turner.com commentedComment #3
dave reidSo 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.
Comment #4
dave reidComment #5
dave reidI 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.
Comment #6
dave reidSo #736066: ajax.js insert command sometimes wraps content in a div, potentially producing invalid HTML and other bugs is our root issue, changed as of Drupal 8.6. Relevant change record: https://www.drupal.org/node/2940704
Comment #7
dave reidThis 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.
Comment #8
effulgentsia commentedComment #9
dave reidFixed errant semicolon in docs.
Comment #10
berdirThanks 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.
Comment #12
berdir