Fix CKEditor plugin translations not filtered on AJAX.
Closes #3516264
Merge request reports
Activity
added 687 commits
-
276297b4...e0a4d441 - 686 commits from branch
project:11.x
- 69aa0617 - Fix CKEditor plugin translations not filtered on AJAX.
-
276297b4...e0a4d441 - 686 commits from branch
168 } 169 170 namespace Drupal\ckeditor5\Hook; 171 172 if (!function_exists('_ckeditor5_get_langcode_mapping')) { 173 174 /** 175 * Mock language mapping between Drupal and CKEditor 5. 176 * 177 * @param string|bool $lang 178 * The Drupal langcode to match. 179 * 180 * @return array|mixed|string 181 * The associated CKEditor 5 langcode. 182 */ 183 function _ckeditor5_get_langcode_mapping($lang = FALSE) { 165 $this->assertEquals($expected_javascript, $javascript); 166 } 167 168 } 169 170 namespace Drupal\ckeditor5\Hook; 171 172 if (!function_exists('_ckeditor5_get_langcode_mapping')) { 173 174 /** 175 * Mock language mapping between Drupal and CKEditor 5. 176 * 177 * @param string|bool $lang 178 * The Drupal langcode to match. 179 * 180 * @return array|mixed|string 163 // There was no placeholder to get the weight from. 164 $expected_javascript['keep_this']['weight'] = 0; 165 $this->assertEquals($expected_javascript, $javascript); 166 } 167 168 } 169 170 namespace Drupal\ckeditor5\Hook; 171 172 if (!function_exists('_ckeditor5_get_langcode_mapping')) { 173 174 /** 175 * Mock language mapping between Drupal and CKEditor 5. 176 * 177 * @param string|bool $lang 178 * The Drupal langcode to match. 318 foreach ($assets->getAlreadyLoadedLibraries() as $library) { 319 if (str_starts_with($library, 'core/ckeditor5.translations.')) { 320 $filter_scripts = TRUE; 321 break; 322 } 323 } 324 } 314 325 // This file is used to get a weight that will make it possible to aggregate 315 326 // all translation files in a single aggregate. 316 327 $ckeditor_dll_file = 'core/assets/vendor/ckeditor5/ckeditor5-dll/ckeditor5-dll.js'; 317 if (isset($javascript[$placeholder_file])) { 328 if ($filter_scripts) { 318 329 // Use the placeholder file weight to set all the translations files 319 330 // weights so they can be aggregated together as expected. 320 $default_weight = $javascript[$placeholder_file]['weight']; 331 $default_weight = $javascript[$placeholder_file]['weight'] ?? 0; If this runs on an AJAX call and the placeholder library/script had already been included once (either during the original page load or as the result of a previous AJAX call), the placeholder script will not be included in the
$javascript
list again, but at least one translation library will be present in the list of already loaded libraries. Evencore/ckeditor5.translations.en
gets set as already loaded when no true translations are needed. Without this additional loop you instead get every possible translation script for all the loaded plugins, as filtering gets skipped completely.This was the easiest way I found to detect that translations need to be filtered [again] without the placeholder script being present.
Since the placeholder script isn't part of the list anymore, we also need to come up with another default value for the weight to avoid a notice for reading a missing key.