Problem/Motivation

Given that the ckeditor module is enabled, when adding a new text format and selecting "ckeditor" in the Text editor select field, a javascript error is thrown.

 f.format_tags.split

This is caused by the Internal ckeditor plugin (\Drupal\ckeditor\Plugin\CKEditorPlugin\Internal::generateFormatTagsSetting()).

The method is returning an empty array when the editor is not associated with a filter format.

The documentation for that method is also wrong. It says that the return value is an array, but that is not true.
When the editor is associated with a text format, the return value is a string with tags separated with a semi-colon (;)
i.e "h1;h2;h3.."

Proposed resolution

Seems like returning an empty string instead of an empty array causes other javascript errors, so my guess is that the
$config["format_tags"] should not even exists when the editor is not associated with a filter format.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

anon created an issue. See original summary.

anon’s picture

Also noticed that this issue blocks javascripts tests from testing stuff in the text format add form.

anon’s picture

Issue summary: View changes
anon’s picture

Title: Uncaught TypeError: f.format_tags.split is not a function » Adding new text format gives Uncaught TypeError: f.format_tags.split is not a function

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

thpoul’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

Nice catch! Manually tested and I was able to replicate the bug and confirm that the patch works great. We should have some testing for it.

Just a nit:

+++ b/core/modules/ckeditor/src/Plugin/CKEditorPlugin/Internal.php
@@ -342,14 +342,15 @@ public function getButtons() {
+   * @return string|false

s/string|false/mixed

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Martijn de Wit’s picture

Status: Needs work » Needs review
FileSize
1.54 KB

Still encountered this issue at 8.6.

Converted patch to 8.6/8.7
Added comment from #6

Wim Leers’s picture

Reproduced. Ran into it over at #3060749: entity_embed_filter_format_edit_form_validate() Logic is Faulty.

Best of all: there is an explicit JS test over there! We can reuse that here, to justify the core fix :)

borisson_’s picture

Status: Needs review » Needs work

So I think #13 means this already had to go back to needs work. But I have some additional nitpicks. The only one actually being actionable being the second.

  1. +++ b/core/modules/ckeditor/src/Plugin/CKEditorPlugin/Internal.php
    @@ -116,8 +116,8 @@ public function getConfig(Editor $editor) {
    +    if (in_array('Format', $toolbar_buttons) && $format_string = $this->generateFormatTagsSetting($editor)) {
    +      $config['format_tags'] = $format_string;
         }
    

    I personally don't like doing assingments in if statements, however I don't see a way to do this in a cleaner way, without introducing more nesting. So let's keep it like this in this case.

  2. +++ b/core/modules/ckeditor/src/Plugin/CKEditorPlugin/Internal.php
    @@ -344,14 +344,15 @@ public function getButtons() {
    +   * @return string|false/mixed
    

    false/mixed is not a valid type I think, we should probably keep just the false and remove the /mixed.

  3. +++ b/core/modules/ckeditor/src/Plugin/CKEditorPlugin/Internal.php
    @@ -344,14 +344,15 @@ public function getButtons() {
    -      return [];
    +      return FALSE;
    

    So the docs say that this used to return an empty array or a string. That doesn't make sense.

    I was going to complain about introducing a mixed return type where it might've been avoidable, but it looks like this was already broken.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Martijn de Wit’s picture

Made patch working for > 8.8.7

Hardik_Patel_12’s picture

Status: Needs work » Needs review
Martijn de Wit’s picture

Status: Needs review » Needs work

It was still on needs work because tests are needed.

pratik_kamble’s picture

Assigned: Unassigned » pratik_kamble
pratik_kamble’s picture

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

douggreen’s picture

The solution fixes the problem. I understand why we hold up merging this waiting on tests ... but this is a pretty fundamental broken feature (adding buttons to the editor) that takes some skill to work around. Can we consider merging this without tests?

raman.b’s picture

Adding a failing test case to demonstrate the reported issue. CKEditor plugin settings are not visible without applying this patch

Also this should address #14

The last submitted patch, 24: 2763075-24-test-only.patch, failed testing. View results

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

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.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

Status: Needs review » Reviewed & tested by the community

Manually reproduced, with this patch applied it works correctly! 👍

Thanks, @raman.b for adding the failing test case!

The last submitted patch, 24: 2763075-24-test-only.patch, failed testing. View results

The last submitted patch, 24: 2763075-24-test-only.patch, failed testing. View results

alexpott’s picture

Version: 9.3.x-dev » 9.2.x-dev
Status: Reviewed & tested by the community » Fixed

Committed and pushed 190aae1079 to 9.3.x and c051ff7508 to 9.2.x. Thanks!

Backported to 9.2.x since this is a low-risk bug fix.

  • alexpott committed 190aae1 on 9.3.x
    Issue #2763075 by raman.b, Martijn de Wit, anon, borisson_: Adding new...

  • alexpott committed c051ff7 on 9.2.x
    Issue #2763075 by raman.b, Martijn de Wit, anon, borisson_: Adding new...

Status: Fixed » Closed (fixed)

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