- Use
hook_ckeditor5_plugin_info_alter
to alter "ckeditor5_codeBlock
" plugin. - Add relevant languages to "
ckeditor5_codeBlock
" config.
/**
* hook_ckeditor5_plugin_info_alter().
*/
function thefirstcode_ckeditor5_plugin_info_alter(array &$plugin_definitions): void {
assert($plugin_definitions['ckeditor5_codeBlock'] instanceof CKEditor5PluginDefinition);
if ($code_block = $plugin_definitions['ckeditor5_codeBlock']) {
$code_block_definition = $code_block->toArray();
$code_block_definition['ckeditor5']['config']['codeBlock'] = [
'languages' => [
[
'language' => 'css',
'label' => 'CSS',
],
[
'language' => 'html',
'label' => 'HTML',
],
[
'language' => 'javascript',
'label' => 'JavaScript',
],
[
'language' => 'php',
'label' => 'PHP',
],
[
'language' => 'twig',
'label' => 'TWIG',
],
[
'language' => 'yaml',
'label' => 'YAML',
],
],
];
$plugin_definitions['ckeditor5_codeBlock'] = new CKEditor5PluginDefinition($code_block_definition);
}
}