4

Following drupal handbook I've created configuration entity type. All works fine except that I have to create ~100 default entities. It would be significantly easier to maintain these default entities if I could define them in a single YML file but that does not work as expected.

If I create files like this:

config/install/example.entity.id1.yml
config/install/example.entity.id2.yml
config/install/example.entity.id3.yml

The config entities are created correctly. However if I create one file config/install/example.entity.yml:

id1:
  field1: val1
  field2: val2

id2:
  field1: val1
  field2: val3

id3:
  field1: val4
  field2: val12

Drupal creates simple config with key example.entity. I'd expected it to create config entities as defined in schema file.

It would be real pain to manage those default config entities with 100 separate files instead of having everything in one yml file. Is this expected behaviour?

0

2 Answers 2

3

According to Configuration Storage in Drupal 8:

Configuration Entities must each be put into their own YAML files, and they should be generated by having the module write out its configuration (don't try writing them by hand).

So it sounds like what you're experiencing is indeed the expected behaviour, and for the time being at least, you'll need to separate each default entity into its own YAML file.

1
  • 1
    I can write a generator for my own use but I already feel sorry for anyone who'll have to manage those files in the future. Commented Jan 11, 2016 at 19:03
1

Little note to the yml code in the question.

In the drupal handbook looks the yml code for example/config/schema/example.schema.yml like this:

example.example.*:
  type: config_entity
  label: 'Example config'
  mapping:
    id:
      type: string
      label: 'ID'
    label:
      type: label
      label: 'Label'

In this case should the yml files, which are in the directory example/config/install, have the following names:

  • example.example.entity.id1.yml
  • example.example.entity.id2.yml
  • example.example.entity.id3.yml

And the code of the yml files should contain also ids:

id: 1
label: Some text

(I've had similar problems as @SiliconMind and needed some time to find the correct way to add the default configuration...).

Your Answer

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

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