Loading core/modules/contextual/contextual.libraries.yml +0 −1 Original line number Diff line number Diff line Loading @@ -12,7 +12,6 @@ drupal.contextual-links: dependencies: - core/jquery - core/drupal - core/drupal.ajax - core/drupalSettings - core/once - core/drupal.touchevents-test Loading core/modules/contextual/js/contextual.js +17 −11 Original line number Diff line number Diff line Loading @@ -180,13 +180,19 @@ // Perform an AJAX request to let the server render the contextual links // for each of the placeholders. if (uncachedIDs.length > 0) { $.ajax({ url: Drupal.url('contextual/render'), type: 'POST', data: { 'ids[]': uncachedIDs, 'tokens[]': uncachedTokens }, dataType: 'json', success(results) { Object.entries(results).forEach(([contextualID, html]) => { const data = new URLSearchParams(); uncachedIDs.forEach((id) => data.append('ids[]', id)); uncachedTokens.forEach((id) => data.append('tokens[]', id)); const req = new Request(Drupal.url('contextual/render'), { method: 'POST', body: data, }); fetch(req) .then((res) => res.json()) .then((json) => Object.entries(json).forEach(([contextualID, html]) => { // Store the metadata. storage.setItem(`Drupal.contextual.${contextualID}`, html); // If the rendered contextual links are empty, then the current Loading @@ -207,9 +213,9 @@ initContextual($placeholders.eq(i), html); } } }); }, }); }), ) .catch((error) => console.warn(error)); } }, }; Loading Loading @@ -532,6 +538,6 @@ * @listens event:drupalContextualLinkAdded */ $(document).on('drupalContextualLinkAdded', (event, data) => { Drupal.ajax.bindAjaxLinks(data.$el[0]); Drupal.ajax?.bindAjaxLinks(data.$el[0]); }); })(jQuery, Drupal, drupalSettings, window.JSON, window.sessionStorage); core/modules/contextual/src/Element/ContextualLinks.php +7 −0 Original line number Diff line number Diff line Loading @@ -76,7 +76,10 @@ public static function preRenderLinks(array $element) { // Transform contextual links into parameters suitable for links.html.twig. $links = []; $use_ajax = FALSE; foreach ($items as $class => $item) { // Check whether any of the contextual links have the use-ajax class. $use_ajax = $use_ajax || in_array('use-ajax', $item['localized_options']['class'] ?? [], TRUE); $class = Html::getClass($class); $links[$class] = [ 'title' => $item['title'], Loading @@ -84,6 +87,10 @@ public static function preRenderLinks(array $element) { ]; } $element['#links'] = $links; if ($use_ajax) { // Add AJAX library if any of the links need it. $element['#attached']['library'][] = 'core/drupal.ajax'; } // Allow modules to alter the renderable contextual links element. static::moduleHandler()->alter('contextual_links_view', $element, $items); Loading core/modules/navigation/tests/src/FunctionalJavascript/PerformanceTest.php +2 −2 Original line number Diff line number Diff line Loading @@ -94,9 +94,9 @@ public function testLogin(): void { 'CacheTagInvalidationCount' => 0, 'CacheTagLookupQueryCount' => 13, 'ScriptCount' => 3, 'ScriptBytes' => 167569, 'ScriptBytes' => 140083, 'StylesheetCount' => 2, 'StylesheetBytes' => 45450, 'StylesheetBytes' => 44024, ]; $this->assertMetrics($expected, $performance_data); Loading core/modules/system/tests/modules/js_testing_ajax_request_test/js/js_testing_ajax_request_test.js +9 −0 Original line number Diff line number Diff line Loading @@ -20,4 +20,13 @@ window.drupalCumulativeXhrCount = 0; htmx.on('htmx:beforeSend', increment); htmx.on('htmx:afterRequest', decrement); } // Catch calls to native fetch(). const oldFetch = window.fetch; window.fetch = function newFetch(resource, options) { increment(); return oldFetch(resource, options).then((res) => { decrement(); return res; }); }; })(jQuery, window.htmx); Loading
core/modules/contextual/contextual.libraries.yml +0 −1 Original line number Diff line number Diff line Loading @@ -12,7 +12,6 @@ drupal.contextual-links: dependencies: - core/jquery - core/drupal - core/drupal.ajax - core/drupalSettings - core/once - core/drupal.touchevents-test Loading
core/modules/contextual/js/contextual.js +17 −11 Original line number Diff line number Diff line Loading @@ -180,13 +180,19 @@ // Perform an AJAX request to let the server render the contextual links // for each of the placeholders. if (uncachedIDs.length > 0) { $.ajax({ url: Drupal.url('contextual/render'), type: 'POST', data: { 'ids[]': uncachedIDs, 'tokens[]': uncachedTokens }, dataType: 'json', success(results) { Object.entries(results).forEach(([contextualID, html]) => { const data = new URLSearchParams(); uncachedIDs.forEach((id) => data.append('ids[]', id)); uncachedTokens.forEach((id) => data.append('tokens[]', id)); const req = new Request(Drupal.url('contextual/render'), { method: 'POST', body: data, }); fetch(req) .then((res) => res.json()) .then((json) => Object.entries(json).forEach(([contextualID, html]) => { // Store the metadata. storage.setItem(`Drupal.contextual.${contextualID}`, html); // If the rendered contextual links are empty, then the current Loading @@ -207,9 +213,9 @@ initContextual($placeholders.eq(i), html); } } }); }, }); }), ) .catch((error) => console.warn(error)); } }, }; Loading Loading @@ -532,6 +538,6 @@ * @listens event:drupalContextualLinkAdded */ $(document).on('drupalContextualLinkAdded', (event, data) => { Drupal.ajax.bindAjaxLinks(data.$el[0]); Drupal.ajax?.bindAjaxLinks(data.$el[0]); }); })(jQuery, Drupal, drupalSettings, window.JSON, window.sessionStorage);
core/modules/contextual/src/Element/ContextualLinks.php +7 −0 Original line number Diff line number Diff line Loading @@ -76,7 +76,10 @@ public static function preRenderLinks(array $element) { // Transform contextual links into parameters suitable for links.html.twig. $links = []; $use_ajax = FALSE; foreach ($items as $class => $item) { // Check whether any of the contextual links have the use-ajax class. $use_ajax = $use_ajax || in_array('use-ajax', $item['localized_options']['class'] ?? [], TRUE); $class = Html::getClass($class); $links[$class] = [ 'title' => $item['title'], Loading @@ -84,6 +87,10 @@ public static function preRenderLinks(array $element) { ]; } $element['#links'] = $links; if ($use_ajax) { // Add AJAX library if any of the links need it. $element['#attached']['library'][] = 'core/drupal.ajax'; } // Allow modules to alter the renderable contextual links element. static::moduleHandler()->alter('contextual_links_view', $element, $items); Loading
core/modules/navigation/tests/src/FunctionalJavascript/PerformanceTest.php +2 −2 Original line number Diff line number Diff line Loading @@ -94,9 +94,9 @@ public function testLogin(): void { 'CacheTagInvalidationCount' => 0, 'CacheTagLookupQueryCount' => 13, 'ScriptCount' => 3, 'ScriptBytes' => 167569, 'ScriptBytes' => 140083, 'StylesheetCount' => 2, 'StylesheetBytes' => 45450, 'StylesheetBytes' => 44024, ]; $this->assertMetrics($expected, $performance_data); Loading
core/modules/system/tests/modules/js_testing_ajax_request_test/js/js_testing_ajax_request_test.js +9 −0 Original line number Diff line number Diff line Loading @@ -20,4 +20,13 @@ window.drupalCumulativeXhrCount = 0; htmx.on('htmx:beforeSend', increment); htmx.on('htmx:afterRequest', decrement); } // Catch calls to native fetch(). const oldFetch = window.fetch; window.fetch = function newFetch(resource, options) { increment(); return oldFetch(resource, options).then((res) => { decrement(); return res; }); }; })(jQuery, window.htmx);