1

I have a module config settings.yml file with a dynamic list of the fields attached to a user entity, eg

archive:
  directory: user-history/archive/
  filename: user-history-archive
  max_cardinality: 5
base_fields:
  uid: true
  name: true
  pass: true
  mail: true
  timezone: true
  status: true
  roles: true
  created: true
  changed: true
  access: true
  login: true
  init: true
  langcode: true
  preferred_langcode: true
  preferred_admin_langcode: true
attached_fields:
  field_alpha_text: 1
  field_beta_term: 1
  field_paragraph: 1
  field_user_story: 1
  user_picture: 0
  field_delta_value: 1
no_change:
  ignore: true
  delete: ''

I am unable to find out how this structure should be described in the module schema.yml file so that config_inspector does not flag the schema as invalid.

I have tried vaiations on

user_history.settings:
  type: config_object
  label: 'User history settings'
  mapping:
    no_change:
      type: mapping
      label: 'No change'
      mapping:
        ignore:
          type: boolean
          label: 'Ignore records with no change'
        delete:
          type: string
          label: 'Delete "no change" records older than'
        batch:
          type: integer
          label: 'Batch size for "no change" record delete'
    base_fields:
      type: mapping
      label: 'Base fields to be tracked'
      mapping:
        uid:
          type: boolean
          label: 'Uid'
        name:
          type: boolean
          label: 'Name'
        pass:
          type: boolean
          label: 'Password'
        mail:
          type: boolean
          label: 'Mail'
        timezone:
          type: boolean
          label: 'Timezone'
        status:
          type: boolean
          label: 'Status'
        roles:
          type: boolean
          label: 'Roles'
        created:
          type: boolean
          label: 'Created'
        changed:
          type: boolean
          label: 'Changed'
        access:
          type: boolean
          label: 'Last access'
        login:
          type: boolean
          label: 'Login'
        init:
          type: boolean
          label: 'Initial mail'
        langcode:
          type: boolean
          label: 'Langcode'
        preferred_langcode:
          type: boolean
          label: 'Preferred langcode'
        preferred_admin_langcode:
          type: boolean
          label: 'Preferred admin langcode'
    attached_fields:
      type: mapping
      label: 'Attached fields to be tracked'
      mapping:
        attached_fields.%key:
          type: integer
          label: [label]
    archive:
      type: mapping
      label: 'Archive settings'
      mapping:
        directory:
          type: string
          label: 'Directory for archive files'
        filename:
          type: string
          label: 'Name for archive files'
        max_cardinality:
          type: integer
          label: 'Maximum field cardinality for separate column values'

but without success.

Any suggestions please?

1
  • I have edited the question to show the full settings.yml and schema.yml files in place of the snippets originally posted in the hope that this might help someone to understand the problem.
    – jlscott
    May 19, 2021 at 3:33

1 Answer 1

0

I think this might be covered under the #Defining a new schema subheading here https://www.drupal.org/docs/drupal-apis/configuration-api/configuration-schemametadata#sequence-definitions

I tried to do this using a mapping type and couldn't get it to work, but switching to a sequence does, because a sequence is for identically typed subkeys, whereas a mapping means you might have different subtypes. When to use mapping or sequence to define an array in a schema file?

For a dynamic mapping, use instead the sequence type:

my_module.settings:
  type: config_object
  label: 'My module settings'
  mapping:
    node_type:
      type: sequence
      label: "List of node types"
      sequence:
        type: string
        label: "Node type key"

This allows arbitrary key -> (string)values beneath the node_type key in your schema.yml

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.