Problem/Motivation

When using CKEditor 5, there is a default set of markup languages provided (see screenshot below). But to fully make use of the plugin we would like to change that list to match the list provided by the field_highlightjs module. That would allow all code blocks to be added easily and then highlighted accordingly. Right now many of the languages can not be enabled in CKEditor 5.

Steps to reproduce

  1. Enable the field_highlightjs (optional) and drupal:ckeditor5 modules
  2. Change text editor setting to ckeditor5 for full_html (/admin/config/content/formats/manage/full_html)
  3. Create a new page with the full_html filter selected for the body field (/node/add/page)
  4. Paste the text below into the body field while in source code mode.
  5. Save the page.
<pre><code class="language-html">
  <marquee>Hello, world!</marquee>
< /code></pre>
<pre><code class="language-bash">
        #!/bin/bash
        ###### CONFIG
        ACCEPTED_HOSTS="/root/.hag_accepted.conf"
        BE_VERBOSE=false
        if [ "$UID" -ne 0 ]
        then
         echo "Superuser rights required"
         exit 2
        fi
        genApacheConf(){
         echo -e "# Host ${HOME_DIR}$1/$2 :"
        }
        echo '"quoted"' | tr -d \" &gt; text.txt
< /code></pre>

As a result of the hardcoded configuration in CKEditor 5 for the codeBlock plugin the bash code will receive an extra language-plaintext class before the one that we set with language-bash. This results in the markup being highlighted as plain text.

Proposed resolution

Allow for configuration of the codeblock plugin of CKEditor 5 in Drupal core. I tried the following without effect:

Before
no ability to configure the Code Block plugin, which means a hardcoded set of languages is available to choose in CKEditor 5
After
the list of languages is now configurable, and the same hardcoded set of languages is the default configuration, which means there's no functional change

Furthermore, based on the feedback at #3269387-8: Drupal 10 & CKEditor 5 support and #3269387-9: Drupal 10 & CKEditor 5 support, this simple feature is sufficient for https://www.drupal.org/project/codesnippet to become obsolete when upgrading from CKEditor 4 to CKEditor 5, much like we previously did with #3274278: Migrate "codetag" contrib CKEditor 4 plugin to built-in equivalent in core's CKEditor 5.

Release notes snippet

The CKEditor code block is now configurable, allowing the list of languages that can be input to be changed in the editor configuration. Modules or install profiles that provide default editor configurations may need to update their shipped config.

CommentFileSizeAuthor
#69 3282233-69.patch23.64 KBWim Leers
#69 interdiff.txt3.04 KBWim Leers
#69 Screenshot 2023-04-26 at 6.10.47 PM.png111.39 KBWim Leers
#66 interdiff.txt771 byteslauriii
#66 3282233-66.patch23.88 KBlauriii
#63 interdiff.txt1.28 KBlauriii
#63 3282233-63.patch23.84 KBlauriii
#62 interdiff.txt3.27 KBlauriii
#62 3282233-62.patch23.43 KBlauriii
#56 Screenshot 2023-04-26 at 6.10.47 PM.png111.39 KBWim Leers
#56 Screenshot 2023-04-26 at 6.10.36 PM.png32.24 KBWim Leers
#53 3282233-53.patch22.82 KBWim Leers
#53 interdiff.txt1.35 KBWim Leers
#52 3282233-52.patch22.83 KBWim Leers
#52 interdiff.txt3.72 KBWim Leers
#49 3282233-48.patch21.87 KBWim Leers
#49 interdiff.txt2.47 KBWim Leers
#47 3282233-47.patch19.51 KBWim Leers
#47 interdiff.txt1.39 KBWim Leers
#46 3282233-46.patch19.77 KBWim Leers
#46 interdiff.txt5.83 KBWim Leers
#43 3282233-43.patch14.21 KBmherchel
#42 3282233-42.patch13.9 KBmherchel
#41 3282233-41.patch7.83 KBmherchel
#40 3282233-37.patch8.66 KBmherchel
#38 3282233-37.patch8.66 KBmherchel
#38 interdiff-3349740-4-3282233-37.txt616 bytesmherchel
#31 Full_HTML___Drupal-3.png47.46 KBmherchel
#30 Full_HTML___Drupal-2.png16.96 KBmherchel
#30 Full_HTML___Drupal.png58.39 KBmherchel
#27 3282233-27-D10.patch16.65 KBWim Leers
#25 3282233-24.patch20.12 KBalexverb
#22 3282233-21.patch23.04 KBalexverb
#20 3282233-20.patch22.72 KBalexverb
#19 3282233-19.patch21.91 KBalexverb
#15 3282233-15.patch18.34 KBalexverb
#14 3282233-14.patch18.06 KBalexverb
#13 cke5-tests-only.patch2.49 KBWim Leers
#10 Screenshot from 2022-05-26 15-58-29.png6.35 KBalexverb
Screenshot from 2022-05-25 12-26-12.png87.93 KBalexverb

Issue fork drupal-3282233

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

alexverb created an issue. See original summary.

alexverb’s picture

Version: » 1.0.0-alpha1
Issue summary: View changes
alexverb’s picture

Project: Field highlightjs » Drupal core
Version: 1.0.0-alpha1 » 10.0.x-dev
Component: Code » ckeditor5.module
Priority: Major » Normal

Moving this issue over to Drupal core (ckeditor5.module) to get support.

alexverb’s picture

Issue summary: View changes
Wim Leers’s picture

Title: Unable to change Ckeditor5 codeblock plugin configuration » Unable to add new language (e.g. "bash") to CKEditor 5 CodeBlock plugin configuration
Category: Support request » Feature request

You're right — #3263384: Add ckeditor5-code-block package and CodeBlock plugin added the Code Block plugin, but did not yet allow any configuration:

ckeditor5_codeBlock:
  ckeditor5:
    plugins:
      - codeBlock.CodeBlock
      - htmlSupport.GeneralHtmlSupport
    config:
      # The CodeBlock plugin supports only `<pre><code>…< /code></pre>`.
      # Configure GHS to support `<pre>…</pre>` markup as well.
      htmlSupport:
        allow:
          -
            name: pre
  drupal:
    label: Code Block
    library: ckeditor5/drupal.ckeditor5.codeBlock
    admin_library: ckeditor5/admin.codeBlock
    toolbar_items:
      codeBlock:
        label: Code Block
    elements:
      - <pre>
      - <code class="language-*">

We can (and should) totally add that. It just was not necessary for feature parity with CKEditor 4. Hence it's not a stable blocker. We're first tackling stable blockers.

We'll get to this after CKEditor 5 is stable!

Wim Leers’s picture

Actually … would you be interested in contributing this feature? 🤓

You'd need to do this:

    drupal:
      label: Code Block
      library: ckeditor5/drupal.ckeditor5.codeBlock
      admin_library: ckeditor5/admin.codeBlock
+     class: Drupal\ckeditor5\Plugin\CKEditor5Plugin\CodeBlock
      toolbar_items:
        codeBlock:
          label: Code Block
      elements:
        - <pre>
        - <code class="language-*">

… and then copy/paste \Drupal\ckeditor5\Plugin\CKEditor5Plugin\Heading, rename it to CodeBlock, and modify it to be about languages to support 😊

alexverb’s picture

Assigned: Unassigned » alexverb

Thanks Wim! For sure I will have a look at contributing this. I didn't know where to start. Now I have an idea.

Wim Leers’s picture

Awesome! 😄

alexverb’s picture

Version: 10.0.x-dev » 9.3.x-dev
Status: Active » Needs review
FileSize
6.35 KB

Hey Wim, I've created a merge request. I would like to get a review.

Remaining issue:

One thing I still can not seem to figure out is how to update the dropdown list in Ckeditor code block button. It keeps displaying the list from config provided by the vendor javascript file: https://github.com/drupal/core/blob/9.4.x/assets/vendor/ckeditor5/code-b...

Dropdown list not updated

Everything else looks like it is working properly:

  • Configuration form for codeblock displays languages defined in core/modules/ckeditor5/ckeditor5.ckeditor5.yml
  • Configuration form can be overriden by the hook hook_ckeditor5_plugin_info_alter()
  • "Limit allowed HTML tags and correct faulty HTML" properly restricts code tag classes to the defined set of languages.

Questions:

  • I'm not yet familiar with the core test setup. So I did not provide any. What kind of tests should a feature like this receive?
  • Are merge requests usually made against the stable branch? I've targeted 9.3.x.
Wim Leers’s picture

Wow! 🤩 You went all the way! 😄👏 Validation constraints included! Thank you so much!

One thing I still can not seem to figure out is how to update the dropdown list in Ckeditor code block button. It keeps displaying the list from config provided by the vendor javascript file: https://github.com/drupal/core/blob/9.4.x/assets/vendor/ckeditor5/code-b...

Ah, yes!

For that, we need to generate the correct CKEditor 5 JS plugin configuration based on the Drupal-managed/stored configuration. But … I see you already have a ::getDynamicPluginConfig() that looks good. 👏 So what's going on? 🤔

Do you see the JS configuration you would expect if you go to a page where your CKEditor 5 instance is active and you type this in the console?

drupalSettings.editor.formats.basic_html.editorSettings.codeBlock

?

I'm not yet familiar with the core test setup. So I did not provide any. What kind of tests should a feature like this receive?

Great question! For this kind of thing, where all we're doing is non-risky configuration for a CKEditor 5 plugin, what we tend to do is write a unit test for them. (Yes, that is possible thanks to the use of \Drupal\Component\Plugin\ConfigurableInterface! 👍) The unit test basically tests the default configuration plus relevant edge cases you can think of, and verifies that getDynamicPluginConfig() actually generates the expected CKEditor 5 JS plugin configuration.

Examples: \Drupal\Tests\ckeditor5\Unit\HeadingPluginTest, \Drupal\Tests\ckeditor5\Unit\ListPluginTest, \Drupal\Tests\ckeditor5\Unit\AlignmentPluginTest.

Are merge requests usually made against the stable branch? I've targeted 9.3.x.

Usually they actually go against the "next" branch, which right now is 9.5.x. But … the CKEditor 5 module is "special": it is experimental. Which means that every change gets committed to every branch (so currently that is 9.3.x, 9.4.x, 9.5.x and 10.0.x — this is a pretty special time in the Drupal core release cycle — usually it's only two branches!), to make sure that sites/people testing experimental modules are actually testing the latest and greatest.

So: what you did is perfect — once this gets to RTBC we'll just need to create a patch (or multiple) to ensure it passes tests against all those branches. (I'm happy to do that for you if you'd rather not.)

Question

What was this experience like for you? Any and all feedback on the DX would be deeply appreciated 😊 Now is the time when we can still make tweaks. Please be brutally honest 😄 🙏

Wim Leers’s picture

Status: Needs review » Needs work

I think I found the answer to the one problem we were having here: https://git.drupalcode.org/project/drupal/-/merge_requests/2319/diffs#no...

Wim Leers’s picture

FileSize
2.49 KB

BTW, if you want the tests to run a lot faster on this merge request: this patch will run only the CKE5 tests. We'll have to remove it eventually, but while working to get this to pass tests, this can save you a lot of time :) Test results in <10 minutes 👍

alexverb’s picture

Status: Needs work » Needs review
FileSize
18.06 KB

Fixed the config key issue and provided a unit test for checking expected config.

Adding patch to start testing. Left out the quick testing patch because I think I did sufficient local testing.

alexverb’s picture

Provided fix for cSpell and split up HTML and XML. Re-applied and force pushed changes because I had issues with rebasing.

The new configuration for codeBlock config makes other ckeditor5 tests fail. I could try to fix these tests, but I'm expecting it will take me a lot of time to figure out. Especially with my current setup (which is inside of a contrib module codebase). If I have a better local setup for working on core I would probably have less trouble. Which takes me to the question Wim posed:

What was this experience like for you? Any and all feedback on the DX would be deeply appreciated 😊 Now is the time when we can still make tweaks. Please be brutally honest 😄 🙏

Answer:

I love the feedback and help I'm getting to be able to contribute something back.

What I'm currently missing a bit is a quick environment/codebase setup that allows me to easily run and debug the tests locally. Because I was looking for a solution for my contributed module field_highlightjs I tried including a Drupal core codebase setup in there. But this proves to be somewhat annoying.

I would love to know what setup core developers are using to work on the Drupal development codebase. I prefer Docker based setups. But the ones listed here require manual setup steps: https://www.drupal.org/community/contributor-guide/reference-information...

I like 'docker-compose up -d' start working kinda deals. Let me know if there is/are any possibilities I can check out. For now I'm pausing my work on this issue until I switch my setup.

Status: Needs review » Needs work

The last submitted patch, 15: 3282233-15.patch, failed testing. View results

Wim Leers’s picture

RE: contribution experience

I would love to know what setup core developers are using to work on the Drupal development codebase. I prefer Docker based setups. But the ones listed here require manual setup steps: https://www.drupal.org/community/contributor-guide/reference-information...

"Bare metal": natively installed PHP + Apache + MySQL using this guide: https://getgrav.org/blog/macos-monterey-apache-multiple-php-versions. Everything else interferes too much. Core's code base is large. Docker performance on macOS is poor (but I hear this is maybe changing?). Performance matters when running core tests. (Though unit tests are probably fine in Docker too.)

What I'm currently missing a bit is a quick environment/codebase setup that allows me to easily run and debug the tests locally. Because I was looking for a solution for my contributed module field_highlightjs I tried including a Drupal core codebase setup in there. But this proves to be somewhat annoying.

cp core/phpunit.xml.dist core/phpunit.xml and tweak core/phpunit.xml to specify your local DB + URL. As of that point, you can run all tests locally. Also through PHPStorm.

Test failures

The tests that are failing make a ton of sense:

  • CKEditor4to5UpgradeCompletenessTest fails because now that this plugin has been made configurable, our test coverage that verifies that configurable plugins generate the sensible configuration when upgrading from CKE4 is failing. This is good — we need to add that 🤓
  • Drupal\Tests\ckeditor5\Kernel\ConfigurablePluginTest::testDefaults(): same thing — this tests the expected default configuration for each configurable CKEditor 5 plugin. And this one was just made configurable, whereas previously it was not. A simple addition to the expectations will suffice! 🤓
  • SmartDefaultSettingsTest has 2 failing test cases: those that place the CodeBlock toolbar item. Why? Because the default configuration that you just added is now present after upgrading from CKEditor 4. This is also good — we need to update the expectations 🤓
  • ValidatorsTest: fails due to this change:
    +++ b/core/modules/ckeditor5/ckeditor5.ckeditor5.yml
    @@ -238,16 +238,70 @@ ckeditor5_codeBlock:
    -      - <code class="language-*">
    +      - <code class="*">
    

    Why that change? I think we can revert that 😄

Review

See the last bullet above, and:

  1. +++ b/core/modules/ckeditor5/ckeditor5.ckeditor5.yml
    @@ -238,16 +238,70 @@ ckeditor5_codeBlock:
    +      codeBlock:
    +        languages:
    

    Nit: if you move this and everything under it a few lines higher, to before the htmlSupport: line, the diff will become simpler to review 🤓

  2. +++ b/core/modules/ckeditor5/ckeditor5.ckeditor5.yml
    @@ -238,16 +238,70 @@ ckeditor5_codeBlock:
    +          - { language: 'html', label: 'HTML', class: 'language-html language-xml' }
    

    Why two classes here? 🤔

  3. +++ b/core/modules/ckeditor5/src/Plugin/CKEditor5Plugin/CodeBlock.php
    @@ -0,0 +1,214 @@
    +  const DEFAULT_CONFIGURATION = [
    +    'enabled_languages' => [
    +      'bash',
    +      'css',
    +      'diff',
    +      'html',
    +      'javascript',
    +      'json',
    +      'less',
    +      'markdown',
    +      'php',
    +      'scss',
    +      'sql',
    +      'twig',
    +      'xml',
    +      'yaml',
    +    ],
    +  ];
    

    This does not match what's documented upstream as the default:
    https://ckeditor.com/docs/ckeditor5/latest/api/module_code-block_codeblo..., where it says:

    languages: [
    	{ language: 'plaintext', label: 'Plain text' }, // The default language.
    	{ language: 'c', label: 'C' },
    	{ language: 'cs', label: 'C#' },
    	{ language: 'cpp', label: 'C++' },
    	{ language: 'css', label: 'CSS' },
    	{ language: 'diff', label: 'Diff' },
    	{ language: 'html', label: 'HTML' },
    	{ language: 'java', label: 'Java' },
    	{ language: 'javascript', label: 'JavaScript' },
    	{ language: 'php', label: 'PHP' },
    	{ language: 'python', label: 'Python' },
    	{ language: 'ruby', label: 'Ruby' },
    	{ language: 'typescript', label: 'TypeScript' },
    	{ language: 'xml', label: 'XML' }
    ]
    
    

    Why is that?

  4. +++ b/core/modules/ckeditor5/src/Plugin/CKEditor5Plugin/CodeBlock.php
    @@ -0,0 +1,214 @@
    +  public function getElementsSubset(): array {
    +    $enabled_languages = $this->getEnabledLanguages();
    +    $plugin_definition = $this->getPluginDefinition();
    +    $all_elements = $plugin_definition->getElements();
    +    $subset = HTMLRestrictions::fromString(implode($all_elements));
    +    $classes = [];
    +    foreach ($plugin_definition->getCKEditor5Config()['codeBlock']['languages'] as $configured_language) {
    +      if (in_array($configured_language['language'], $enabled_languages, TRUE)) {
    +        $classes[] = $configured_language['class'] ?? 'language-' . $configured_language['language'];
    +      }
    +    }
    +    $element_string = '<pre> <code class=' . '"' . implode(' ', $classes) . '"' . '>';
    +    $subset = $subset->intersect(HTMLRestrictions::fromString($element_string));
    +
    +    return $subset->toCKEditor5ElementsArray();
    +  }
    

    I think this could be a lot simpler. Something like this:

        $subset = $this->getPluginDefinition()->getElements();
        $subset = array_diff($subset, ['<code class="language-*">']);
        foreach ($plugin_definition->getCKEditor5Config()['codeBlock']['languages'] as $configured_language) {
          if (in_array($configured_language['language'], $enabled_languages, TRUE)) {
            $class = $configured_language['class'] ?? 'language-' . $configured_language['language'];
            $subset[] = sprintf('<code class="%s">', $class);
          }
        }
        return $subset;
    
  5. +++ b/core/modules/ckeditor5/tests/src/Unit/CodeBlockPluginTest.php
    @@ -0,0 +1,182 @@
    +    // This matches the language list from ckeditor5.ckeditor5.yml so our test
    +    // will fail whenever that list is altered. That is because removing a
    +    // language could result in the allowed tags being altered.
    +    $all_languages = [
    +      ['language' => 'plaintext', 'label' => 'Plain text'],
    +      ['language' => 'accesslog', 'label' => 'Apache Access Log'],
    +      ['language' => 'bash', 'label' => 'Bash'],
    +      ['language' => 'c', 'label' => 'C'],
    +      ['language' => 'cpp', 'label' => 'C++'],
    +      ['language' => 'csharp', 'label' => 'C#'],
    +      ['language' => 'css', 'label' => 'CSS'],
    +      ['language' => 'diff', 'label' => 'Diff'],
    +      ['language' => 'dockerfile', 'label' => 'Dockerfile'],
    +      ['language' => 'go', 'label' => 'Go'],
    +      ['language' => 'groovy', 'label' => 'Groovy'],
    +      ['language' => 'html', 'label' => 'HTML', 'class' => 'language-html language-xml'],
    +      ['language' => 'http', 'label' => 'HTTP'],
    +      ['language' => 'ini', 'label' => 'TOML, also INI'],
    +      ['language' => 'java', 'label' => 'Java'],
    +      ['language' => 'javascript', 'label' => 'JavaScript'],
    +      ['language' => 'json', 'label' => 'JSON'],
    +      ['language' => 'kotlin', 'label' => 'Kotlin'],
    +      ['language' => 'less', 'label' => 'Less'],
    +      ['language' => 'lua', 'label' => 'Lua'],
    +      ['language' => 'makefile', 'label' => 'Makefile'],
    +      ['language' => 'markdown', 'label' => 'Markdown'],
    +      ['language' => 'nginx', 'label' => 'Nginx config'],
    +      ['language' => 'objectivec', 'label' => 'Objective-C'],
    +      ['language' => 'perl', 'label' => 'Perl'],
    +      ['language' => 'pgsql', 'label' => 'PostgreSQL and PL/pgSQL'],
    +      ['language' => 'php', 'label' => 'PHP'],
    +      ['language' => 'php-template', 'label' => 'PHP Template'],
    +      ['language' => 'python', 'label' => 'Python'],
    +      ['language' => 'python-repl', 'label' => 'Python REPL'],
    +      ['language' => 'r', 'label' => 'R'],
    +      ['language' => 'ruby', 'label' => 'Ruby'],
    +      ['language' => 'rust', 'label' => 'Rust'],
    +      ['language' => 'scss', 'label' => 'SCSS'],
    +      ['language' => 'shell', 'label' => 'Shell Session'],
    +      ['language' => 'sql', 'label' => 'SQL'],
    +      ['language' => 'swift', 'label' => 'Swift'],
    +      ['language' => 'twig', 'label' => 'Twig'],
    +      ['language' => 'typescript', 'label' => 'TypeScript'],
    +      // cSpell:disable
    +      ['language' => 'vbnet', 'label' => 'Visual Basic .NET'],
    +      ['language' => 'vbscript', 'label' => 'VBScript'],
    +      ['language' => 'vbscript-html', 'label' => 'VBScript in HTML'],
    +      // cSpell:enable
    +      ['language' => 'xml', 'label' => 'XML'],
    +      ['language' => 'yaml', 'label' => 'YAML'],
    +    ];
    

    That is a lot of repetition/duplication 😅 I agree with the sentiment, but in this case it might be a bit much?

    Would you be opposed to applying the pattern from \Drupal\Tests\ckeditor5\Unit\LanguagePluginTest::buildExpectedDynamicConfig(), to avoid having this list hardcoded in two places?

  6. +++ b/core/modules/ckeditor5/tests/src/Unit/CodeBlockPluginTest.php
    @@ -0,0 +1,182 @@
    +    $default_language_ids = [
    +      'bash',
    +      'css',
    +      'diff',
    +      'javascript',
    +      'json',
    +      'less',
    +      'markdown',
    +      'php',
    +      'scss',
    +      'sql',
    +      'twig',
    +      'xml',
    +      'yaml',
    +    ];
    

    Can't this be simplified to $default_language_ids = CodeBlock::DEFAULT_CONFIGURATION? 🤓

alexverb’s picture

Hi Wim, thanks for your extensive review. I'll reply to your points. I did some research on them before making the changes. I think I may have valid reasons for some of them.

RE: Review

1. Nit: if you move this and everything under it a few lines higher, to before the htmlSupport: line, the diff will become simpler to review

The htmlSupport key is part of the main ckeditor properties because it its not listed under the codeBlock properties:

So according to the functionality of ckeditor5 this is the correct way to set them.

2. Why two classes here?

I did think about keeping language-html and language-xml seperated with a single class as Ckeditor5 sets it like that. But since I'm working on the contrib field_highlightjs there the highlighting is the same for html and xml under the key language-xml (https://highlightjs.org/download/#download-form).

I applied this change for two reasons:

  • it serves as an example for users that are looking how to set the class (could be done by documentation as well).
  • it shows an example of multiple language classes
    • where the primary class has priority in showing the language label inside of ckeditor
    • where the secondary class allows highlighting such as highlightjs to still perform the highlighting

3. This does not match what's documented upstream as the default

You are right. I decided to change the list of enabled_languages. I went back and forth on that because I also thought about not deviating from Ckeditors defaults. But I decided against keeping the default for three reasons:

  • Keeping the default from ckeditor would result in enabled_languages being the same as the available languages. Thus making the configuration form somewhat redundant since all would be selected. Then you could only disable languages.
  • Instead I chose to copy the list of most common languages provided by highlightjs (https://highlightjs.org/download/#download-form). This results in the user being able to enable more common languages if they please.
  • I did make a "personal preference" selection of enabled_languages based on which languages Drupal comes the most in contact with. This list is very much up for debate. Since end users may not neccessarily be interested in Drupal only like me.

I'm open to any suggestions. I would even revert back to the default settings that Ckeditor5 provides. But I thought it would be nice to have 34 common languages available instead of only 14 languages and have them be active. The contrib field_highlightjs module I'm working on will eventually make all 197 languages available.

4. I think this could be a lot simpler.

In this case I think you are right. I do not fully understand how one plugin can have an effect on the other. So I wanted to keep using the subset diff, merge and/or intersect functionality. It is pretty complicated to me. I will try your suggestion.

5. That is a lot of repetition/duplication 😅 I agree with the sentiment, but in this case it might be a bit much?

Yes I thought the same thing. Also went a bit back and forth on that. The benefit of duplicating it really supports "a very" edge case where Drupal core would change the list with a removal. I'm ok with removing the duplication and relying on config and code.

Recap

So for 1 and 2 I would like to keep this as is. Maybe provide documentation somewhere on point 2 so people know they have the option to add or alter classes. The functionality on dual classes does work as expected.

For point 3 I think maybe we should open a discussion on what the list of available languages should be. And what the list of enabled languages should be. I simply applied a personal preference because I thought it would be sad to have core be limited to only 14 languages.

Point 4 and 5 I will change according to your review.

RE:RE: contribution experience

I still love Docker too much to go back to a local development setup. I'm currently setting up a .gitlab-ci.yml pipeline for my field_highlightjs project. With things like DrupalPod, Gitpod, Github Codespaces, Vscode.dev, Cloud9 etc. I think many opensource projects will move there entirely. And with Drupal being in Gitlab alpha phase there will be a need do provide that environment anyway to run the tests. But I love the overall direction Drupal is going. I hope I can still make some suggestions for the gitlab pipelines for contributed projects.

PS: Question: Do you happen to know people that can get me onto Drupal Gitlab Alpha at https://git.drupalcode.org/ ? I'm now working on https://gitlab.com/ to be able to run tests and find out a good way to mix/match contrib and core code setups. I think it is essential to be able to easily contribute to Drupal core through a contributed module. And that running Drupal tests and codechecks should be performed the same way. Even though I would love to see Drupal move onto Grumphp.

RE: Test failures

I've almost finished my test setup for my field_highlightjs project. When that's done I will tackle the remaining failing tests at ckeditor5. Glad these are expected failures. Anyway, it may now take a couple of days before you see changes. I hope to get some other things done in the meantime.

alexverb’s picture

Re-running tests with suggestions applied.

alexverb’s picture

More test fixes to test.

Wim Leers’s picture

+++ b/core/modules/ckeditor5/ckeditor5.ckeditor5.yml
@@ -238,16 +238,38 @@ ckeditor5_codeBlock:
-      - <code class="language-*">
+      - <code class="*">

This change is causing the last test failure.

And … this should not actually work! You should get the validation error

The "ode" HTML tag has an attribute restriction "*". This implies all attributes are allowed. Remove the attribute restriction instead, or use a prefix (`*-foo`), infix (`*-foo-*`) or suffix (`foo-*`) wildcard restriction instead.

Ah, no, that is for the attribute name, not the attribute value.

Congrats, you've found an edge case for which we did not yet have an explicit validation check! 🤓😄 Created #3284254: HTMLRestrictions should not allow <tag attr="*"> because that is equivalent to <tag attr> for addressing that.

alexverb’s picture

Status: Needs work » Needs review
FileSize
23.04 KB

Fixed last test. Requesting review, if it is green at least.

I still stayed with <code class> without the wildcard. Since that means the same. Reason I went away from <code class="language-*"> is because when there is a language that has a class that does not start with "language-" I could not get the subset to resolve properly.

Class names are open to CKE5: https://ckeditor.com/docs/ckeditor5/latest/features/code-blocks.html
We just happen to provide the language- prefix.

Wim Leers’s picture

Status: Needs review » Needs work

#22:

that has a class that does not start with "language-" I could not get the subset to resolve properly.

  1. When does that happen? That seems like it should not be allowed? Even if classnames are technically arbitrarily nameable upstream, that doesn't mean that we need to allow that! I think requiring a language- prefix is A) totally reasonable, B) more predictable. I think we should enforce that restriction. We could even add an assert() to ::getDynamicPluginConfig() to prevent people from altering the metadata in this way.
  2. If the subset does not resolve properly, that'd be a bug.

Patch review

Excellent work here! 👍👏

  1. +++ b/core/modules/ckeditor5/ckeditor5.ckeditor5.yml
    @@ -238,16 +238,38 @@ ckeditor5_codeBlock:
    -      - <code class="language-*">
    +      - <code class>
    

    👎 This is effectively saying that this plugin can generate any value for the class attribute. That is not true.

  2. +++ b/core/modules/ckeditor5/src/Plugin/CKEditor4To5Upgrade/Contrib.php
    @@ -53,7 +55,32 @@ public function mapCKEditor4SettingsToCKEditor5Configuration(string $cke4_plugin
        */
       public function computeCKEditor5PluginSubsetConfiguration(string $cke5_plugin_id, FilterFormatInterface $text_format): ?array {
    -    throw new \OutOfBoundsException();
    +    switch ($cke5_plugin_id) {
    +      case 'ckeditor5_codeBlock':
    +        $restrictions = $text_format->getHtmlRestrictions();
    +        if ($restrictions === FALSE) {
    

    👏 NICE! 😄

    But this means we should have explicit upgrade path test coverage. You can achieve that by adding a new text format + editor (just like $basic_html_format_with_pre does) and adding a new test case to \Drupal\Tests\ckeditor5\Kernel\SmartDefaultSettingsTest::provider() 😊

  3. +++ b/core/modules/ckeditor5/src/Plugin/CKEditor4To5Upgrade/Contrib.php
    @@ -53,7 +55,32 @@ public function mapCKEditor4SettingsToCKEditor5Configuration(string $cke4_plugin
    +        if (isset($restrictions['allowed']['code']['class'])
    +        && ($classes = $restrictions['allowed']['code']['class'])
    +        && is_array($classes)) {
    

    🤓 Interesting indentation here, and also very interesting that phpcs does not complain about this. Core does not allow this kind of formatting.

  4. +++ b/core/modules/ckeditor5/src/Plugin/CKEditor4To5Upgrade/Contrib.php
    @@ -53,7 +55,32 @@ public function mapCKEditor4SettingsToCKEditor5Configuration(string $cke4_plugin
    +              return in_array('language-' . $enabled_language, $classes);
    

    🤓 Nit: Drupal core always uses strict in_array() checks, so could you specify the third parameter? 🙏

  5. +++ b/core/modules/ckeditor5/src/Plugin/CKEditor5Plugin/CodeBlock.php
    @@ -0,0 +1,222 @@
    +      if (in_array($language, self::ALWAYS_ENABLED_LANGUAGES, TRUE)) {
    

    👍 Like here!

  6. +++ b/core/modules/ckeditor5/src/Plugin/CKEditor5Plugin/CodeBlock.php
    @@ -0,0 +1,222 @@
    +  public static function getStaticPluginConfig(): array {
    

    🤔 This should be private: we don't want this to become a public API that we must continue to support forever! This is only called from the unit test — then this should be a private helper on the unit test instead.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

alexverb’s picture

Ok Wim,

I went back to only allowing <code class="language-*"> classes. But for this I had to remove subset functionality to limit the allowed tags to only the enabled language classes. This is documented in a code comment why it is currently not possible. Because attribute values do not have the functionality to diff wildcards such as attributes themselves can. So it is not really a bug, but rather a non-existing feature.

For the rest I fixed the location for the static config function. I hope my tests are still green.

Wim Leers’s picture

Title: Unable to add new language (e.g. "bash") to CKEditor 5 CodeBlock plugin configuration » Ability to configure additional languages (e.g. "bash" or "SQL") for CKEditor 5 CodeBlock plugin
Priority: Normal » Major
Status: Needs review » Needs work
Issue tags: +rc target

#25 is now in fact possible — #3284254: HTMLRestrictions should not allow <tag attr="*"> because that is equivalent to <tag attr> has been fixed!

Furthermore, based on the feedback at #3269387-8: Drupal 10 & CKEditor 5 support and #3269387-9: Drupal 10 & CKEditor 5 support, I'm now convinced that implementing this simple feature is sufficient for https://www.drupal.org/project/codesnippet to become obsolete when upgrading from CKEditor 4 to CKEditor 5, much like we previously did with #3274278: Migrate "codetag" contrib CKEditor 4 plugin to built-in equivalent in core's CKEditor 5.

Wim Leers’s picture

The last commit (0f8c5c47) does not apply cleanly to D10: a small conflict needs to be resolved. Let's see how this would do on D10.


This one's for you, @Steffen Schlaer!

Note that because of limitations in the current patch, you'll for now have to manually modify core/modules/ckeditor5/ckeditor5.ckeditor5.yml, and add something like this:

          - { language: 'sql', label: 'SQL' }

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Wim Leers’s picture

mherchel’s picture

This is a solid starting point, but I fear that people will keep asking for more languages. We may need to have better configurability, similar to what we have for the Style plugin… although that does result in a more complex configuration UI. I think that may be reasonable though.

💯💯💯

The current patch UI is this:

My use case is that I want to add support for YML, bash, etc.

I would love (and expect) to be able to do something like this:

mherchel’s picture

FileSize
47.46 KB

Note the @lauriii's patch in #3349740: CK5 code block languages are not configurable implements this. Thoughts on continuing with that patch?

Screenshot:

Wim Leers’s picture

Does the CKEditor 5 plugin actually support arbitrary languages? According to https://ckeditor.com/docs/ckeditor5/latest/features/code-blocks.html#con..., it does.

I'd like to avoid adding more of this thing|label\n-style syntax. That's why I think checkboxes are nice. Can you think of a scalable UI pattern that is more userfriendly than a <textarea> with a bunch of custom syntax?

mherchel’s picture

Can you think of a scalable UI pattern that is more userfriendly than a with a bunch of custom syntax?

I can't think of any that's in use within Drupal core.

Would you be in favor of adding thing|label\n syntax (which is used throughout core) and then creating a followup issue to change the UI?

Wim Leers’s picture

Assigned: alexverb » Unassigned
Issue tags: +Needs followup

Discussed this with @mherchel in Drupal Slack: https://drupal.slack.com/archives/C01GWN3QYJD/p1680107668028699.

He convinced me that we shouldn't hold this issue up on improving the UI. That is an independent problem that affects many UIs in Drupal core. This single one isn't going to make the difference. Plus, this introduces the opportunity to in the future fix two config UIs at the same time: that for the Style CKEditor 5 plugin and that of the CodeBlock plugin!

The crucial requirement for that is already present: store the settings in a structured way, so that the UI is decoupled from the exact syntax in that <textarea>. Or rather, it's partially present in the Drupal\ckeditor5\Plugin\CKEditor5Plugin\CodeBlock class in the current MR, it's 100% present in \Drupal\ckeditor5\Plugin\CKEditor5Plugin\Style. This MR can copy/paste the pattern already established in Drupal core 👍

So: +1 for @mherchel's proposal in #31, and let's create a follow-up for that improved UI 😊

lauriii’s picture

+1 that it would be nice to something like what #32 is describing. However, it's not super straight forward to build a UI like this like I discovered with @timplunkett on #2521800: List key|label entry field is textarea, which doesn't give guidance towards the expected input. Because of that, I think it would be perfectly fine to leave that for a follow-up as suggested by #34. 👍

Wim Leers’s picture

Oh wow, that'd be another place where that same pattern is used, and that same follow-up should target that too! 👍 In fact … that issue SHOULD be the follow-up! 😄

Done: #2521800-27: List key|label entry field is textarea, which doesn't give guidance towards the expected input.

GREAT 😄

mherchel’s picture

Attaching the patch from #3349740: CK5 code block languages are not configurable

This was originally created by @lauriii, and then had some code formatting changes done by @TanujJain-TJ (adding credit now).

The patch still isn't passing code checks, so I'm attaching one more interdiff from the patch here, and hopefully it will pass.

Still needs tests.

mherchel’s picture

Version: 9.5.x-dev » 10.1.x-dev
mherchel’s picture

FileSize
8.66 KB

Attaching the same patch, but running against 10.1.x

mherchel’s picture

FileSize
7.83 KB

Previous patch had an xdebug_break(); in it. Yanking that out.

mherchel’s picture

Status: Needs work » Needs review
FileSize
13.9 KB

New patch adds a Nightwatch test to verify the functionality of the new editable code block languages.

There's still some legitimate CK5 kernel tests failing, so this will still fail.

mherchel’s picture

Updating dictionary.txt

Status: Needs review » Needs work

The last submitted patch, 43: 3282233-43.patch, failed testing. View results

Wim Leers’s picture

Issue tags: -Needs tests
  1. +++ b/core/modules/ckeditor5/config/schema/ckeditor5.schema.yml
    @@ -141,6 +141,31 @@ ckeditor5.plugin.media_media:
    +      sequence:
    +        type: mapping
    +        label: 'Language'
    +        mapping:
    +          label:
    +            type: label
    +            label: 'Language label'
    +          language:
    +            type: string
    +            label: 'Language key'
    

    🤩 This keeps the door open for a better UI in the future! 👏 (see #34 & #36) — and it matches the pattern used by the Style plugin.

  2. +++ b/core/modules/ckeditor5/config/schema/ckeditor5.schema.yml
    @@ -141,6 +141,31 @@ ckeditor5.plugin.media_media:
    +      orderby: ~
    

    👍 I first thought this should be orderby: key, but actually this is better: it allows the administrator to control in which order the languages are presented to the end user 👍

  3. +++ b/core/modules/ckeditor5/config/schema/ckeditor5.schema.yml
    @@ -141,6 +141,31 @@ ckeditor5.plugin.media_media:
    +      constraints:
    +        NotBlank:
    +          message: "Enable at least one language, otherwise disable the Code Block plugin."
    +        UniqueLabelInList:
    +          labelKey: label
    

    👍 This also matches the pattern established by the Style plugin.

  4. +++ b/core/modules/ckeditor5/src/Plugin/CKEditor5Plugin/CodeBlock.php
    @@ -0,0 +1,150 @@
    +  public static function parseLanguagesFromValue(string $form_value): array {
    

    🐛 This should be protected, not public.

    The reference \Drupal\ckeditor5\Plugin\CKEditor5Plugin\Style::parseStylesFormValue() was public to allow \Drupal\ckeditor5\Plugin\CKEditor4To5Upgrade\Core::mapCKEditor4SettingsToCKEditor5Configuration() to reuse it. That's not needed here.

  5. +++ b/core/modules/ckeditor5/src/Plugin/CKEditor5Plugin/CodeBlock.php
    @@ -0,0 +1,150 @@
    +  public function getElementsSubset(): array {
    +    return array_column($this->configuration['languages'], 'language');
    +  }
    

    🐛 This is incorrect. This returns

    ['plaintext', 'c', 'cs', 'cpp', 'css', 'diff', …]
    

    But it really intended to generate:
    <code class="language-plaintext language-c language-cs language-cpp language-css language-diff …">.

    We could absolutely implement it that way.

    But … that actually comes with a pretty significant downside: it would mean that if the site administrator later changed the available languages that existing content (text stored in the DB) would not longer be considered valid. The set of languages that are configured here could easily evolve over time.

    So I think that in this case, not implementing CKEditor5PluginElementsSubsetInterface and ALWAYS returning <code class="language-*"> would actually be reasonable.

  6. 🤩 The Nightwatch test looks awesome!
Wim Leers’s picture

Status: Needs work » Needs review
FileSize
5.83 KB
19.77 KB
  • StandardTest fails because editor.editor.full_html has not been updated to include the configuration for the codeBlock plugin.
  • ConfigurablePluginTest and SmartDefaultSettingsTest fail for a similar reason but instead of changing code we need to change test expectations: there now is default configuration, and we're not yet expecting that in these tests.

These all just require me to copy over \Drupal\ckeditor5\Plugin\CKEditor5Plugin\CodeBlock::defaultConfiguration(), so doing that to hopefully enable this patch to still land in 10.1 😊

Wim Leers’s picture

ValidatorsTest fails due to the bug I pointed out in #45.5. I can fix that by just deleting a few LoC!

Now tests should pass.

The last submitted patch, 46: 3282233-46.patch, failed testing. View results

Wim Leers’s picture

+++ b/core/modules/ckeditor5/ckeditor5.post_update.php
@@ -89,3 +89,19 @@ function ckeditor5_post_update_plugins_settings_export_order(&$sandbox = []) {
+/**
+ * Updates Text Editors using CKEditor 5 Code Block.
+ */
+function ckeditor5_post_update_code_block(&$sandbox = []) {
+  $config_entity_updater = \Drupal::classResolver(ConfigEntityUpdater::class);
+  $config_entity_updater->update($sandbox, 'editor', function (Editor $editor): bool {
+    // Only try to update editors using CKEditor 5.
+    if ($editor->getEditor() !== 'ckeditor5') {
+      return FALSE;
+    }
+    $settings = $editor->getSettings();
+
+    return in_array('codeBlock', $settings['toolbar']['items'], TRUE);
+  });
+}

🐛 This does not actually update the configuration.

… and that would've been caught by an update test 😅

I know these tests can be a PITA to write, but I've done it so many times at this point that I figure I'd do that for you, @mherchel.

(It's 99% copy/paste of \Drupal\Tests\ckeditor5\Functional\Update\CKEditor5UpdatePluginSettingsSortTest, so I don't think this should prevent me from RTBC'ing it after the update path logic is added and the test is passing.)

The last submitted patch, 47: 3282233-47.patch, failed testing. View results

Wim Leers’s picture

Assigned: Unassigned » mherchel
Status: Needs review » Needs work

For #49 and #45.4.

Wim Leers’s picture

Assigned: mherchel » Unassigned
Status: Needs work » Needs review
FileSize
3.72 KB
22.83 KB

@mherchel told me he's traveling to a Drupal conference and asked me to write the update path (#49) and fix the nit (#45.4).

Unfortunately, this means I can in principle no longer RTBC this … even though I really only made trivial additions to help get this across the finish line. 😞

Wim Leers’s picture

I made a small mistake in #46: I appended the ckeditor5_codeBlock config at the end, but thanks to config schema's orderby, it should've have been sorted by key — thankfully ConfigImportAllTest caught that 😊

The last submitted patch, 52: 3282233-52.patch, failed testing. View results

mglaman’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +MidCamp2023

Great! This helps unblock my blog migration to D10. @mherchel demoed this to me at MidCamp.

Wim Leers’s picture

Improved the issue summary.

Wim Leers’s picture

Issue summary: View changes

Fix markup.

Wim Leers’s picture

Issue summary: View changes

Drupal.org's code filter is horribly broken 🥲

Wim Leers’s picture

Issue summary: View changes
Issue tags: -rc target

Untagging rc target and moving the relevant information out of #26 into the issue summary instead.

Wim Leers’s picture

Dear reviewer:

+++ b/core/modules/ckeditor5/src/Plugin/CKEditor5Plugin/CodeBlock.php
@@ -0,0 +1,138 @@
+class CodeBlock extends CKEditor5PluginDefault implements CKEditor5PluginConfigurableInterface {
...
+  public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
...
+  public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
...
+  protected static function parseLanguagesFromValue(string $form_value): array {
...
+  public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {

Note that all of this closely resembles the logic in \Drupal\ckeditor5\Plugin\CKEditor5Plugin\Style.

Run diff core/modules/ckeditor5/src/Plugin/CKEditor5Plugin/Style.php core/modules/ckeditor5/src/Plugin/CKEditor5Plugin/CodeBlock.php to convince yourself.

catch’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/ckeditor5/ckeditor5.post_update.php
@@ -89,3 +89,43 @@ function ckeditor5_post_update_plugins_settings_export_order(&$sandbox = []) {
+      $settings = $editor->getSettings();
+      // @see \Drupal\ckeditor5\Plugin\CKEditor5Plugin\CodeBlock::defaultConfiguration()
+      $settings['plugins']['ckeditor5_codeBlock'] = [
+        'languages' => [
+          ['label' => 'Plain text', 'language' => 'plaintext'],
+          ['label' => 'C', 'language' => 'c'],
+          ['label' => 'C#', 'language' => 'cs'],
+          ['label' => 'C++', 'language' => 'cpp'],
+          ['label' => 'CSS', 'language' => 'css'],
+          ['label' => 'Diff', 'language' => 'diff'],
+          ['label' => 'HTML', 'language' => 'html'],
+          ['label' => 'Java', 'language' => 'java'],
+          ['label' => 'JavaScript', 'language' => 'javascript'],
+          ['label' => 'PHP', 'language' => 'php'],
+          ['label' => 'Python', 'language' => 'python'],
+          ['label' => 'Ruby', 'language' => 'ruby'],
+          ['label' => 'TypeScript', 'language' => 'typescript'],
+          ['label' => 'XML', 'language' => 'xml'],
+        ],
+      ];
+      $editor->setSettings($settings);

This needs to happen in a hook_entity_presave() so that it also applies to config entities that are exported in install profiles or modules. Then the post update itself just needs to save the config entity and the changes will be applied here too.

Agreed with improving the UI in the follow-up identified. I did not review the entire patch.

lauriii’s picture

Status: Needs work » Needs review
FileSize
23.43 KB
3.27 KB

This should address #61.

lauriii’s picture

Addressing the PHPCS violation.

mherchel’s picture

Status: Needs review » Reviewed & tested by the community

Just tested patch #63, and it works as expected! Looked through code, and seems logical (as far as I can tell).

RTBC (pending tests passing)

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 63: 3282233-63.patch, failed testing. View results

lauriii’s picture

Status: Needs work » Needs review
FileSize
23.88 KB
771 bytes

Looks like I forgot to apply this only for editors with CKEditor 5 🤦‍♂️

Wim Leers’s picture

Status: Needs review » Reviewed & tested by the community

There was only a random functional JS test failure in a test unrelated to CKEditor 5.

Re-testing and back to RTBC.

catch’s picture

Status: Reviewed & tested by the community » Needs review
  1. +++ b/core/modules/ckeditor5/ckeditor5.module
    @@ -648,3 +650,34 @@ function _ckeditor5_theme_css($theme = NULL): array {
    + */
    +function ckeditor5_entity_presave(EntityInterface $entity) {
    +  if ($entity instanceof Editor && $entity->getEditor() === 'ckeditor5') {
    +    $settings = $entity->getSettings();
    +    if (in_array('codeBlock', $settings['toolbar']['items'], TRUE) && !isset($settings['plugins']['ckeditor5_codeBlock'])) {
    

    Can this use hook_editor_presave()?

  2. +++ b/core/modules/ckeditor5/ckeditor5.post_update.php
    @@ -89,3 +89,18 @@ function ckeditor5_post_update_plugins_settings_export_order(&$sandbox = []) {
    + */
    +function ckeditor5_post_update_code_block(&$sandbox = []) {
    +  $config_entity_updater = \Drupal::classResolver(ConfigEntityUpdater::class);
    +  $config_entity_updater->update($sandbox, 'editor', function (Editor $editor): bool {
    +    // Only try to update editors using CKEditor 5.
    +    if ($editor->getEditor() !== 'ckeditor5') {
    +      return FALSE;
    +    }
    

    This looks good.

+++ b/core/modules/ckeditor5/src/Plugin/CKEditor5Plugin/CodeBlock.php
@@ -0,0 +1,138 @@
+      '#title' => $this->t('Code Block Languages'),
+      '#type' => 'textarea',
+      '#description' => $this->t('A list of code block languages that will be provided in the "Code Block" dropdown. Enter one value per line, in the format key|label. Example: php|PHP'),
+    ];

Should this be 'A list of languages'. 'code block languages' looks like a type of language, but we just mean languages available for the code block plugin. Or should it even say 'Programming languages' to avoid confusion with the other sort of language?

+++ b/core/modules/ckeditor5/src/Plugin/CKEditor5Plugin/CodeBlock.php
@@ -0,0 +1,138 @@
+    $form['languages'] = [
+      '#title' => $this->t('Code Block Languages'),
+      '#type' => 'textarea',

Same question with 'Languages' vs. 'Code block languages' - depends on context in the UI I guess.

I'm assuming we don't have code block enabled in any existing configuration so no shipped config to update?

Wim Leers’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community
FileSize
111.39 KB
3.04 KB
23.64 KB
  • #68.1: It could, but it shouldn't? 🤔 This is a concern of the CKEditor 5 text editor plugin, not of the generic Text Editor module? For [#3293540], we also added the update logic (ckeditor_post_update_omit_settings_for_disabled_plugins()) to the ckeditor module, not the editor module?

    D'oh, now I understand. You were worried that this is now running for every entity save instead of just Editor entities! 😅

    ✅ Done! Matched the pattern established by comment_entity_view_display_presave(), layout_builder_entity_view_display_presave() etc.

  • RE: "code block languages" → https://ckeditor.com/docs/ckeditor5/latest/features/code-blocks.html#con... uses both terms. Even though e.g. HTML and SQL aren't programming languages, I agree that this is a clearer term.

    ✅ Done. Updated UI:

  • I'm assuming we don't have code block enabled in any existing configuration so no shipped config to update?

    Correct. 👍 In more detail: Full HTML has the codeBlock plugin enabled, but there was indeed no configuration for it, hence no config was ever shipped. (That's why the update path test makes grateful use of that existing config entity to prove that the necessary default configuration is now added.)

lauriii’s picture

I also tried to address the feedback. Our interdiffs were identical with one exception:

+++ b/core/modules/ckeditor5/src/Plugin/CKEditor5Plugin/CodeBlock.php
@@ -25,9 +25,9 @@ class CodeBlock extends CKEditor5PluginDefault implements CKEditor5PluginConfigu
+      '#title' => $this->t('Programming Languages'),

We may want to have a lowercase l on languges but other than that looks good. This could be fixed on commit.

catch’s picture

In more detail: Full HTML has the codeBlock plugin enabled, but there was indeed no configuration for it, hence no config was ever shipped.

What about core/profiles/standard/config/install/editor.editor.full_html.yml - if that's re-exported, won't it have the code block config added?

lauriii’s picture

+++ b/core/modules/ckeditor5/tests/src/Nightwatch/Tests/ckEditor5CodeSyntaxTest.js
--- a/core/profiles/standard/config/install/editor.editor.full_html.yml
+++ b/core/profiles/standard/config/install/editor.editor.full_html.yml

+++ b/core/profiles/standard/config/install/editor.editor.full_html.yml
@@ -32,6 +32,50 @@ settings:
+    ckeditor5_codeBlock:

Isn't that use case covered by this?

  • catch committed 0c59ee88 on 10.1.x
    Issue #3282233 by alexverb, Wim Leers, mherchel, lauriii, Tanuj.:...
catch’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Fixed
Issue tags: +10.1.0 release notes, +10.1.0 release highlights

. Even though e.g. HTML and SQL aren't programming languages, I agree that this is a clearer term.

I was going to quietly ignore that (and CSS). Agreed it's clearer if not 100% precise.

We may want to have a lowercase l on languges but other than that looks good. This could be fixed on commit.

Agreed and done.

Isn't that use case covered by this?

Sorry, yes, that's exactly what I meant.

I looked through the rest of the patch and can't find any more to complain about, I am not really qualified to review the nightwatch test but other people have done (and it's well commented and easy enough to follow along).

Added a change record: https://www.drupal.org/node/3356871

Committed/pushed to 10.1.x, thanks!

Wim Leers’s picture

quietone’s picture

I published the change record.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.