Config schema issues with extended DS layouts

Created on 18 September 2024, 4 months ago

Problem/Motivation

At the moment, we cannot define the config schema for layouts that provide extra config and extend Drupal\ds\Plugin\DsLayout.

Steps to reproduce

Say we have this layout definition:

ds_1col_extended:
  label: One column layout (extended)
  class: '\Drupal\my_module\Plugin\DsLayoutExtended'
  ...

Where DsLayoutExtended class defines extra config.
When we try to validate the config with config_inspector, the schema for this extra config is missing.

Proposed resolution

1. Change core.entity_view_display.*.*.*.third_party.ds to use the appropriate layout_plugin.settings.* schema definition
2. Define schema definitions for all layouts shipped by DS.

Remaining tasks

- Do it..
- This may need a change record so site owners are aware they need to define the schema for all custom layouts

User interface changes

N/A

API changes

N/A

Data model changes

N/A

🐛 Bug report
Status

Active

Version

3.0

Component

Code

Created by

🇧🇪Belgium herved

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

Merge Requests

Comments & Activities

  • Issue created by @herved
  • Merge request !37Resolve #3475173 "Config schema issues" → (Open) created by herved
  • Pipeline finished with Success
    4 months ago
    Total: 338s
    #286211
  • Status changed to Needs review 4 months ago
  • 🇧🇪Belgium herved

    MR created, let me know if you have a better idea on the approach.

    This may need a change record so site owners are aware they need to define the schema for all their custom layouts.
    E.g.: If ds_my_layout uses the main Drupal\ds\Plugin\DsLayout class, then we have to use.:

    layout_plugin.settings.ds_my_layout:
      type: ds.layout_plugin.settings.default
    
  • 🇧🇪Belgium herved

    Static patch for composer, if anyone needs it.

  • 🇧🇪Belgium swentel

    Sorry for the delay, patch idea is logical, never thought about that!

    Will double test what happens with custom layouts on existing projects when the schema isn't defined. I wonder if hook_config_schema_info_alter could help here (never ever used that hook, but who knows !)

  • 🇧🇪Belgium herved

    Oh indeed, that could simplify things a lot.
    Maybe loading all DS layouts and setting the default type to ds.layout_plugin.settings.default

  • 🇧🇪Belgium swentel

    So it's not possible (yet) to dynamically add new schema definitions, see Allow adding dynamic configuration schema Needs work and ConfigSchemaAlterException. Bummer, otherwise the code underneath would solve a lot.

    Can't think of any other approach at the moment which doesn't involve warning users that they need to define a schema for the custom layouts in a module or theme. Let me think and experiment a bit more. But even if we don't find another solution, committing this isn't probably that much of a problem as config will still be imported afaik and everything will still keep on working.

    (merged 8.x-3.x with the fork, but no other changes yet)

    /**
     * Implements hook_config_schema_info_alter().
     */
    function ds_config_schema_info_alter(&$definitions) {
      // Bummer, this is not allowed!
      foreach (DS::getLayouts() as $layout_name => $layout) {
        if ($layout->getClass() == 'Drupal\ds\Plugin\DsLayout') {
          $definitions['layout_plugin.settings.' . $layout_name]['type'] = 'ds.layout_plugin.settings.default';
        }
      }
    }
    
  • 🇧🇪Belgium swentel

    Ok tried the following:

    1. Used layout_plugin.settings.ds.[%parent.id] in ds.entity_display.schema.yml
    2. Defined layout_plugin.settings.ds.* to use ds.layout_plugin.settings.default - all layouts should pick this up normally

    config inspector seems happy, let's hope the tests are too :)

  • 🇧🇪Belgium swentel

    Ok, tests are happy! It looks like this might be a good approach and we don't have to warn users to update the schema. We can create a change record though explaining the new feature instead, win-win!

    I'm not missing something am I ? :)

Production build 0.71.5 2024