[Drupal 8] use sed (on OSX) to strip the uuid line from exported config files being used for module default configuration; i.e. [module_name]/config/optional|install
NOTE: this can also by bypassed in the export by using Drupal Cnnsole and including the --remove-uuid
flag. Also using the --remove-config-hash
flag can help prevent additional headaches.
Ex:
drupal config:export --directory=”[full-path-to-location]” --tar --remove-uuid --remove-config-hash
The UUID should never be included when using when using these exported config yaml files as the default configuration pagaged with a custom module. This is suppoedly not to be a thing in the exported yaml files at some point, but until then stripping the uuid line out is a manual process which can be a pain as there can be a lot of files.
To automate this, run the following sed command in the directory containing the yaml files:
sed -i.bak '/^uuid: /d' ./*
The i.bak
arg will create a backup of the affected file. When satistifed with the results, you can safely get rid of the .bak files:
rm *.bak
References:
Thanks for following up. I think we may be missing each other on intention, use case, and process (maybe not, it has been quite a while since I worked on this and I don't know what exactly your use case and or needs are).
First, distributing a UUID with a module is bad practice as it defeats the purpose of a UUID, which is Universally Unique IDentifier. I understand your POV but I can't support this approach, for whatever that's worth, as it is bad practice. The process below should be sufficient to achieve the intention and use case as described below without potential for UUID collision or failure due to its absence. Also, I defer to the drupal.org support docs page (see below) that instructs to remove the UUID row from the config export YAML as part of the process.
The intention: bundle a default default configuration with a custom module to populate the config in the database upon module install.
The use case: distribution of a custom module with a default configuration bundled.
The process (as the module developer):
drush cex
) or full archive export via admin UI (admin/config/development/configuration/full/export).Once you have the module's config YAML:
drush updb
or update database script (/update.php) in browser, to to assure the defaults are picked up.[drupal.org] Include default configuration in your Drupal module - relevant excerpt:
Create a file named node.type.example_mytype.yml and place it in your module's directory in a subdirectory called
config/install
. For example this file could be at /modules/example/config/install/node.type.example_mytype.yml if the module is in /modules/example.) - relevant excerpt:If I remember correctly, the above should be sufficient to the intention and use case as described above. If you wanted to make changes after the module has been published, then you would use the update hook as you described in your last post's update. Again, I think that this is correct. Things may have changed in D9 and or there could be an error in this process recommendation, as I haven't tested this recently or worked with this specifically in ~5-6 years, and your need and use case could be different from what I've described - so your mileage may vary.
Good luck!