function Ckeditor5Hooks::jsAlter
Same name and namespace in other branches
- 11.x core/modules/ckeditor5/src/Hook/Ckeditor5Hooks.php \Drupal\ckeditor5\Hook\Ckeditor5Hooks::jsAlter()
Implements hook_js_alter().
Attributes
#[Hook('js_alter')]
File
-
core/
modules/ ckeditor5/ src/ Hook/ Ckeditor5Hooks.php, line 344
Class
- Ckeditor5Hooks
- Hook implementations for ckeditor5.
Namespace
Drupal\ckeditor5\HookCode
public function jsAlter(&$javascript, AttachedAssetsInterface $assets, LanguageInterface $language) : void {
$placeholder_file = 'core/assets/vendor/ckeditor5/translation.js';
// When the locale module isn't installed there are no translations.
if (!$this->moduleHandler
->moduleExists('locale')) {
unset($javascript[$placeholder_file]);
return;
}
$translations_library = 'core/ckeditor5.translations';
if (in_array($translations_library, $this->libraryDependencyResolver
->getLibrariesWithDependencies($assets->getLibraries()), TRUE) || in_array($translations_library, $this->libraryDependencyResolver
->getLibrariesWithDependencies($assets->getAlreadyLoadedLibraries()), TRUE)) {
// Remove all CKEditor 5 translations files that are not in the current
// language.
$ckeditor5_language = $this->languageMapper
->getMapping($language->getId());
$javascript = array_filter($javascript, function ($item) use ($ckeditor5_language) {
// Skip files that are not CKEditor5 translation files. Remove files
// that don't match the language requested.
return empty($item['ckeditor5_langcode']) || $item['ckeditor5_langcode'] === $ckeditor5_language;
});
}
// The placeholder file is not a real file, remove it from the list.
unset($javascript[$placeholder_file]);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.