- Issue created by @herved
- Status changed to Needs review
4 months ago 11:32am 18 September 2024 - 🇧🇪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.: Ifds_my_layout
uses the mainDrupal\ds\Plugin\DsLayout
class, then we have to use.:layout_plugin.settings.ds_my_layout: type: ds.layout_plugin.settings.default
- 🇧🇪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 tods.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:
- Used layout_plugin.settings.ds.[%parent.id] in ds.entity_display.schema.yml
- 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 ? :)