7

I need to define an array in my onlyone.settings.yml file to store this values:

onlyone_node_types:
  book: book
  test: test

In my onlyone.schema.yml file I have this:

module.settings:
  type: config_object
  label: 'Only One settings'
  mapping:
    onlyone_node_types:
      type: sequence
      label: 'Configured content types to have Only One node'
      sequence:
        type: string
        label: 'Content type machine name'

But I don't know if I need to use a sequence or a mapping type in my case.

I read in the Configuration schema/metadata page this:

Note that you may also encounter a slightly different sequence definition where the type of the sequence items is defined as a strictly one item list. This format is deprecated and will be removed in Drupal 9:

So, I don't know if I need to use mapping or sequence in my case to define my array.

1 Answer 1

12

A sequence is an unlimited list of identically structured elements. A mapping is a limited set of keys, each key has a possibly different structure.

Your key has node types, so you're storing a list of node type ids, which means a sequence with an inner type string. Exactly what you have.

If you'd use a mapping, you could only store book and test, but test could be an integer (or mapping, or sequence, ...) while book is a string.

The note has nothing to do with sequence vs mapping, it just refers to an old way of defining the type in the sequence and would look like this:

onlyone_node_types:
  type: sequence
  label: 'Configured content types to have Only One node'
  sequence:
    -  type: string
       label: 'Content type machine name'

PS: I'd would convert that to a numbered list, which will then be stored like this:

onlyone_node_types:
  - book
  - test
1
  • Is it fair to say a sequence is a collection of mappings?
    – daggerhart
    Jun 26, 2022 at 5:43

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.