Problem/Motivation

Given the following config schema (which stores an array of plugin configurations, keyed by plugin id):

  plugin_configurations:
    type: sequence
    label: 'Plugin configurations'
    sequence:
      - type: <module_name>.<plugin_type>.plugin.[%key]

the magic %key item is very likely to point to a plugin derivative (e.g. entity:node), but config schemas can not be keyed with a wildcard like <module_name>.<plugin_type>.plugin.entity:*.

Proposed resolution

Figure out a solution.

Remaining tasks

Implement the solution :)

User interface changes

None.

API changes

A small API addition.

Comments

vijaycs85’s picture

Issue tags: +Configuration schema, +D8MI

Module name and plugin_type aren't part of config? if yes, we can get them dynamically. Since the issue summary doesn't have the whole schema, I'm assuming config like this:

id: myplugin
module: foo
plugin_id: bar
plugin_configurations:
  - setting1: value1

then schema would be:

module:
  type: string
  label: 'Module'
plugin_id:
  type: string
  label: 'Plugin ID'
plugin_configurations:
  type: [%parent.module].[%parent.plugin_id].plugin.[%parent.id]
  label: 'Configuration'

# plugin config.
foo.bar.plugin.myplugin:
  type: sequence
  label: 'Settings'
  sequence:
    - type: string
      label: 'Setting'

Gábor Hojtsy’s picture

So my understanding this is for cases where %key is compound data in itself and you want to provide schema for wildcard types by breaking up that compound data. One way to do that is if the data contains parts of that compound key as individual data elements, eg. 'generic_type: entity' if 'entity' was part of %key.

amateescu’s picture

Module name and plugin type have nothing to do with the problem here, they were just written in the OP as generic strings. Here is the exact config data and schema which should detail the problem a bit better:

Config data:

...
'datasources' => 
  array (
    0 => 'entity:node',
    1 => 'entity:block_content',
  ),
  'datasource_configs' => 
  array (
    'entity:node' => 
    array (
      'default' => '1',
      'bundles' => 
      array (
        'article' => 0,
        'page' => 0,
      ),
    ),
    'entity:block_content' => 
    array (
      'default' => '1',
      'bundles' => 
      array (
        'basic' => 0,
      ),
    ),
  ),
...

And the config config schema:

...
    datasources:
      type: sequence
      label: 'Datasource plugin IDs'
      sequence:
        - type: string
    datasource_configs:
      type: sequence
      label: 'Datasource plugin configurations'
      sequence:
        # @todo Update when https://www.drupal.org/node/2291073 is fixed.
        - type: search_api.datasource.plugin.[%key]
...

@Gábor Hojtsy, the problem with that approach is that every plugin/config entity author will have to include it manually in their plugin configuration just for the sake of config schema, and I seriously doubt that will happen :/

Gábor Hojtsy’s picture

@amateescu: we do have a history of modifying config structure in the interest of it making sense for schema instead of introducing more exotic typing solutions to core. I think there is a tradeoff there between schema system and docs complexity and some simple patterns that people need to apply. I guess it depends on the solution proposal for this problem :)

vijaycs85’s picture

@amateescu, sorry for #1. I didn't really get the problem.

the problem with that approach is that every plugin/config entity author will have to include it manually in their plugin configuration just for the sake of config schema

Can we create a data type for all common config elements.

...
    datasources:
      type: sequence
      label: 'Datasource plugin IDs'
      sequence:
        - type: string
    datasource_configs:
      type: sequence
      label: 'Datasource plugin configurations'
      sequence:
        # @todo Update when https://www.drupal.org/node/2291073 is fixed.
        - type: search_api.datasource.plugin.[%key]
...

search_api.datasource.plugin.*:
  type: plugin_config
  label: 'Default config'

# Can define plugin that has something special like this:
search_api.datasource.plugin.special:
  type: plugin_config
  label: 'Default config'
  mapping:
   special_foo:
    type: string
    label: 'Bar'


# may be in data_types.schema.yml
plugin_config:
  type: mapping
  label: ''
  mapping:
    default:
      type: boolean
      label: 'Default value'
    bundle:
      type: sequence
      label: 'Bundles'
      sequence:
        - type: string
          label: 'Bundle'
       
Gábor Hojtsy’s picture

I don't think it is at all possible to say plugin config in general will contain a default value especially not boolean default value and that hey would depend on bundles...

Gábor Hojtsy’s picture

Status: Active » Closed (duplicate)
Issue tags: +language-config

Sounds like a duplicate of #2317865: Config schema definitions for plugins aren't applied to their derivatives which was resolved since then.