Problem/Motivation

While working on #2556617: [regression] Disabled format still filters and displays the value and #2555973: Fatal error when editing content after disabling format with editor I found that when a text format is disabled (or enabled) the paired editor is not synchronizing as status. While I cannot see right now an application for this fix, I still think that text format and the editor should be in sync. But it's still a minor issue.

Proposed resolution

Sync the editor status with the corresponding text format status. i.e. when disabling the text format, the text editor should be disabled as well.

Remaining tasks

None.

User interface changes

None.

API changes

None.

Data model changes

None.

Beta phase evaluation

Reference: https://www.drupal.org/core/beta-changes
Issue category Task because adds status synchronization between a text format and its paired editor.
Issue priority Not critical because right now no functionality is broken.
Disruption No disruption
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

claudiu.cristea created an issue. See original summary.

claudiu.cristea’s picture

Patch.

claudiu.cristea’s picture

Issue summary: View changes

Status: Needs review » Needs work

The last submitted patch, 2: 2557265-1-test-only.patch, failed testing.

claudiu.cristea’s picture

Status: Needs work » Needs review

The main patch passed.

Wim Leers’s picture

  1. +++ b/core/modules/editor/src/EventSubscriber/FilterFormatSubscriber.php
    @@ -0,0 +1,54 @@
    +    if (!preg_match('`^filter\.format\.([a-z0-9_]+)$`', $config->getName(), $found) || !$event->isChanged('status')) {
    

    This is sad :(

    Can't we use hook_ENTITY_TYPE_presave()?

  2. +++ b/core/modules/editor/src/Tests/EditorFilterIntegration.php
    @@ -0,0 +1,56 @@
    +  /*
    

    Nit: one missing asterisk :P

claudiu.cristea’s picture

This is sad :(

I would say that the sad part is that we cannot detect the configurable type in a subscriber like this. This makes the config events dispatching/subscribing so useless :(

We can use presave hook but I wonder if we cannot improve the config event dispatching to receive also the type of config along with the event object. Using hooks seems to me a step back now if we already have events.

EDIT: Forget the last paragraph.

claudiu.cristea’s picture

@Wim Leers, OK. Here's one with hook presave.

claudiu.cristea’s picture

FileSize
551 bytes
3.02 KB

Ouch. Forgot the asterisk.

claudiu.cristea’s picture

FileSize
3 KB
1.55 KB

Small fixes in test.

Wim Leers’s picture

Status: Needs review » Needs work

I would say that the sad part is that we cannot detect the configurable type in a subscriber like this. This makes the config events dispatching/subscribing so useless :(

Oh, yes, absolutely. Your patch is great, the API forcing us to do this is sad. I wonder if we're just missing something. But in any case, a cleaner solution exists, using hooks. And I suspect that's exactly why things work the way they do :)

Many thanks for working on this!


I have only nits:

  1. +++ b/core/modules/editor/editor.module
    @@ -509,3 +511,30 @@ function _editor_parse_file_uuids($text) {
    +function editor_filter_format_presave(ConfigEntityInterface $format) {
    

    You can typehint to \Drupal\filter\Entity\FilterFormat :)

  2. +++ b/core/modules/editor/editor.module
    @@ -509,3 +511,30 @@ function _editor_parse_file_uuids($text) {
    +  // The text format being created cannot have an editor yet.
    

    s/an editor/a text editor/

  3. +++ b/core/modules/editor/editor.module
    @@ -509,3 +511,30 @@ function _editor_parse_file_uuids($text) {
    +  /** @var \Drupal\Core\Config\Entity\ConfigEntityInterface $original */
    

    Same typehint.

  4. +++ b/core/modules/editor/editor.module
    @@ -509,3 +511,30 @@ function _editor_parse_file_uuids($text) {
    +  // If the text format status is the same, exit here.
    

    s/exit here/return early/

  5. +++ b/core/modules/editor/editor.module
    @@ -509,3 +511,30 @@ function _editor_parse_file_uuids($text) {
    +  if (($status = $format->status()) == $original->status()) {
    

    Let's use strict equality.

  6. +++ b/core/modules/editor/editor.module
    @@ -509,3 +511,30 @@ function _editor_parse_file_uuids($text) {
    +  /** @var \Drupal\Core\Config\Entity\ConfigEntityInterface $editor */
    

    \Drupal\editor\Entity\Editor

  7. +++ b/core/modules/editor/src/Tests/EditorFilterIntegration.php
    @@ -0,0 +1,56 @@
    +    $editor = Editor::create(['format' => $format->id(), 'editor' => 'unicorn']);
    +    $editor->save();
    

    We don't use $editor anywhere. So can be simplified to Editor::create(…)->save() AFAICT :)

claudiu.cristea’s picture

Status: Needs work » Needs review
FileSize
2.9 KB
2.26 KB

Thank you for review.

Wim Leers’s picture

Issue summary: View changes

I was going to RTBC this, but then I realized that we probably also want to test the inverse direction: when re-enabling a text format, the text editor should be re-enabled also.

Other than that, this looks perfect :)

claudiu.cristea’s picture

FileSize
3.08 KB
793 bytes

OK.

Wim Leers’s picture

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

Wonderful! This is a great patch :)

Without a beta evaluation, this likely won't go in for some time though. But marking RTBC already, to signal that it is indeed ready.

claudiu.cristea’s picture

Issue summary: View changes
Issue tags: -Needs beta evaluation

Beta evaluation.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 14: 2557265-14.patch, failed testing.

claudiu.cristea queued 14: 2557265-14.patch for re-testing.

claudiu.cristea’s picture

Status: Needs work » Reviewed & tested by the community

In #17 it was a random bot failure. Re-RTBC as per #15.

xjm’s picture

Category: Task » Bug report
Priority: Minor » Normal
Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs manual testing, +Needs upgrade path, +Needs upgrade path tests

This sounds like a bug actually, and maybe a bit of a data integrity issue even. What happens in HEAD if a text format with or without existing content is disabled and then someone tries to use the editor for it? What happens if it's disabled and then re-enabled? What happens if one or the other is disabled via a config deployment? Some manual testing of both HEAD and the patch would be good to see what the implications are and if there's a bigger bug lurking here. Anyway, recategorizing the issue so it gets more visibility.

Also, @alexpott and I agreed that this would probably need an upgrade path, particularly for existing sites where text formats had already been disabled, to ensure that the existing configuration is updated and consistent.

claudiu.cristea’s picture

A nice integration of editor with text format would have been if Editor would write its settings directly into format as third-party settings. No more headache :)

EDIT: I see this as typical use-case of third-party settings.

claudiu.cristea’s picture

Issue summary: View changes
Issue tags: -Needs manual testing
FileSize
107.63 KB
58.55 KB

There's no direct effect of this inconsistency in UI. I manually tested this. I created a node with 'basic_html' format (see the first picture) an tried to edit after disabled the format (2nd picture). The body field became disabled but that is the expected behaviour. Then I re-enabled the formatting the API as this cannot be done from UI and the node edit form went to normal as in 1st picture.

After disabling basic_html

claudiu.cristea’s picture

Assigned: Unassigned » Wim Leers
Status: Needs work » Needs review
Issue tags: -Needs upgrade path, -Needs upgrade path tests
FileSize
8.39 KB
6.36 KB
  • Manual tested. See #22.
  • Converted the kernel test to a KernelTestBaseTNG test.
  • Added update path.
  • Added update path test.

Assigning to @Wim Leers for review.

Status: Needs review » Needs work

The last submitted patch, 23: 2557265-23.patch, failed testing.

claudiu.cristea queued 23: 2557265-23.patch for re-testing.

The last submitted patch, 23: 2557265-23.patch, failed testing.

claudiu.cristea queued 23: 2557265-23.patch for re-testing.

Wim Leers’s picture

Assigned: Wim Leers » Unassigned
Status: Needs work » Reviewed & tested by the community

A nice integration of editor with text format would have been if Editor would write its settings directly into format as third-party settings. No more headache :)

Editor module predates the concept of third-party settings.


Upgrade path looks great to me. Just one nit that can be fixed on commit.

+++ b/core/modules/editor/src/Tests/Update/EditorUpdateTest.php
@@ -0,0 +1,75 @@
+    $editor_basic_html =  $config_factory->get('editor.editor.basic_html');

Nit: two spaces instead of one.

claudiu.cristea’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
8.38 KB
1.65 KB

Fixed the double spacing.

Wim Leers’s picture

Status: Needs review » Reviewed & tested by the community

Heh, thanks :) It's fine to keep the patch at RTBC if you're only making whitespace changes ;) :)

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

This has test coverage and upgrade path and fixes a bug so permitted during beta. Committed 40fa14b and pushed to 8.0.x. Thanks!

  • alexpott committed 40fa14b on 8.0.x
    Issue #2557265 by claudiu.cristea, Wim Leers: Synchronize editor status...

Status: Fixed » Closed (fixed)

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