Unable to save text format config form in 10.3

Created on 28 June 2024, 2 months ago
Updated 29 July 2024, about 1 month ago

Problem/Motivation

Saving the text format settings form fails with errors:

    'item' is not a supported key.
    'block' is not a supported key.
    'random' is not a supported key.
    'button' is not a supported key.
    'img' is not a supported key.
    'quote' is not a supported key.
    'clear' is not a supported key.
    'highlight' is not a supported key.
    'link' is an unknown key because filters.shortcode.id is shortcode (see config schema type filter_settings.shortcode).

Steps to reproduce

1. Enable shortcode.
2. Try to save a text format.

Proposed resolution

Add a shortcode.schema.yml file.

This will be tricky because the schema depends on the plugins. I'm not sure how to implement that.

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States mortona2k Seattle

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @mortona2k
  • First commit to issue fork.
  • I get the same error, but only in combination with the CKEditor 5 Plugin Pack β†’ module.

  • πŸ‡ΊπŸ‡ΈUnited States swirt Florida

    I am seeing this same issue and not related to CKEditor5_plugin_pack

  • πŸ‡ΊπŸ‡ΈUnited States swirt Florida

    Our current config prior to 10.3 has this

      shortcode:
        id: shortcode
        provider: shortcode
        status: true
        weight: -50
        settings:
          nhd: '1'
          irf: '1'
          ltch: '1'
    

    The complaint is that

    'nhd' is not a supported key.
    'irf' is not a supported key.
    'ltch' is not a supported key.
    

    What I am not clear on is what the new structure of the config should be.

  • πŸ‡ΊπŸ‡ΈUnited States swirt Florida

    I tried commenting out the validation to see if I could save the form and export the config to see if the config would take on a different structure. It did not.

    The problem seems to be that the file
    /Drupal/Core/Validation/Plugin/Validation/Constraint/ValidKeysConstraintValidator.php validate()
    went through significant refactoring in 10.3 and broke it for shortcode.

  • πŸ‡ΊπŸ‡ΈUnited States swirt Florida

    The problem is that this line

     $dynamically_valid_keys = $mapping->getDynamicallyValidKeys();
    

    is not grabbing the dynamic keys that are in the settings. So they are not present.

  • πŸ‡ΊπŸ‡ΈUnited States swirt Florida

    Bumping this up to a major bug.

  • πŸ‡ΊπŸ‡ΈUnited States swirt Florida

    I believe the shortcode module needs to declare a schema for the settings similar to the way other filter plugins declare them.
    https://api.drupal.org/api/drupal/core%21modules%21filter%21config%21sch...

  • We are using the shortcode module without the base tags, but we have a custom module that uses the shortcode API.

    I am trying to implement the configuration scheme as follows:

    filter_settings.shortcode_plugin:
      type: mapping
      label: 'Shortcode Plugin'
      mapping:
        shortcode_plugin:
          type: boolean
          label: 'Provides a shortcode plugin.'

    It's not enough to implement the schema. We have to edit the plugin file (*Shortcode.php), because of the configuration section.

    use Drupal\Core\Language\Language;
    use Drupal\shortcode\Plugin\ShortcodeBase;
    
    /**
     * The image shortcode.
     *
     * @Shortcode(
     *   id = "button",
     *   title = @Translation("Button"),
     *   description = @Translation("Insert a link formatted like a button.")
     * )
     */
    class ButtonShortcode extends ShortcodeBase {
    ...
    
  • πŸ‡«πŸ‡·France jverneaut

    Like #10, I'm using the shortcode module without the basic tags. After some trial and error, I was able to get the provided shortcode_example module to work by adding the following minimal configuration at shortcode_example/config/schema/shortcode_example.schema.yml where col is the name of its defined shortcode:

    filter_settings.shortcode:
      type: mapping
      mapping:
        col:
          type: boolean
    

    It is therefore possible to add configuration mappings to the base shortcode module from custom shortcode modules which was a sufficient fix in my case to be able to save the text formats.

  • πŸ‡ΊπŸ‡ΈUnited States mortona2k Seattle

    @jverneaut I think the issue is needing to determine the schema dynamically, or populating default values for unused parameters.

    All the shortcode plugins have their own parameters. Are we able to add all the optional parts to the main schema, or does it only work when you explicitly match the schema file with the plugins in use?

    It seems like we need a way to dynamically alter schema?

  • πŸ‡ΊπŸ‡ΈUnited States swirt Florida

    When I was xdebugging some of this I noticed there support for a pattern that is 'settings.*' that other plugins were using. I interpreted that as being essentially allow any settings. Which I think, like mortana2k is suggesting, it a bit more dynamic. I had to step away from this for a bit, so I did not chase that farther.

  • πŸ‡«πŸ‡·France jverneaut

    I dug a little deeper and found in the configuration schema docs β†’ that the appropriate type for configuration objects with unknown keys is actually sequence, I then tried to create a configuration file at /config/schema/shortcode.schema.yml at the root of the base shortcode module with this content and I can then save text formats successfully and the config gets correctly exported.

    filter_settings.shortcode:
      type: sequence
      sequence:
        type: boolean
    
  • πŸ‡ΊπŸ‡ΈUnited States swirt Florida

    Sadly I am away from my machine and can't test this but it seems like the right fix. Nice digging jverneaut.

  • Status changed to RTBC about 2 months ago
  • πŸ‡ΊπŸ‡ΈUnited States swirt Florida

    I was able to test this using simplytest.me and applying the patch

    1. simplytest.me using 10.3.1 and shortcode 2.2 plus patch 14
    2. enabled shortcode basics
    3. went to full html filter
    4. enabled all shortcodes
    5. was able to save the settings without errors

    Nicely done jverneaut. Thank you. Changing to RTBC

  • πŸ‡ΊπŸ‡ΈUnited States swirt Florida

    And on a side note, Welcome to Drupal jverneaut. You've been on Drupal.org for less than 15 hours and already have a successful patch submitted. That is pretty impressive. Cheers.

  • Thank you jverneaut. The patch is working like a charm. I was able to save the settings without errors, and the shortcodes are working as expected.

  • Merge request !6#3457731 - Add schema β†’ (Open) created by rishabjasrotia
  • First commit to issue fork.
  • πŸ‡ΊπŸ‡ΈUnited States nicxvan

    I added the missing newline.

  • πŸ‡ΊπŸ‡ΈUnited States nicxvan

    I had to apply this patch and add this file:

    web/modules/custom/custom_shortcode/config/schema/custom_shortcode.schema.yml

    Then for each custom shortcode I need the following:

    filter_settings.shortcode:
      type: mapping
      mapping:
        custom-shortcode:
          type: boolean
    
  • πŸ‡©πŸ‡°Denmark Steven Snedker

    I'm very impressed with the solution in #14. Repaired the upcoming version of Wayback Filter β†’ as well. Thank you, Julien.

  • Assigned to Denes.Szabo
  • Status changed to Fixed about 1 month ago
  • πŸ‡­πŸ‡ΊHungary Denes.Szabo Hungary

    Thank you guys, nice improvement! Merged.

  • Status changed to Fixed about 1 month ago
  • πŸ‡­πŸ‡ΊHungary Denes.Szabo Hungary
Production build 0.71.5 2024