Updated all the contrib modules to their latest versions.
[yaffs-website] / web / modules / contrib / token / src / Controller / TokenTreeController.php
index f233ab2340941386bc824e2e95b951f5e0331e4f..3edf40229c08c2c59fb677eb4676b46d9b570e4a 100644 (file)
@@ -50,6 +50,17 @@ class TokenTreeController extends ControllerBase {
     $build['#cache']['contexts'][] = 'url.query_args:options';
     $build['#title'] = $this->t('Available tokens');
 
+    // If this is an AJAX/modal request, add a wrapping div to the contents so
+    // that Drupal.behaviors.tokenTree and Drupal.behaviors.tokenAttach can
+    // stil find the elements they need to.
+    // @see https://www.drupal.org/project/token/issues/2994671
+    // @see https://www.drupal.org/node/2940704
+    // @see http://danielnouri.org/notes/2011/03/14/a-jquery-find-that-also-finds-the-root-element/
+    if ($request->isXmlHttpRequest()) {
+      $build['#prefix'] = '<div>';
+      $build['#suffix'] = '</div>';
+    }
+
     return $build;
   }