Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save DavMorr/c3a5b73820778e2fb213cdd9d614f27a to your computer and use it in GitHub Desktop.
Save DavMorr/c3a5b73820778e2fb213cdd9d614f27a to your computer and use it in GitHub Desktop.
Drupal 8 - use sed to strip uuid line from exported config files

[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:

@welly
Copy link

welly commented Mar 5, 2024

@gaellafond

Config included in /config/install is default config. When you import config from a module, a UUID gets generated for that config and the config from the module you installed is never used again unless you uninstall and reinstall the module. At which point, another UUID will be generated.

When you export site config - drush cex - the config that was installed from the module will be exported into your config sync directory with the UUID intact. Default module config doesn't need a UUID to behave correctly and for Drupal to know what needs to be updated because once it's initially installed, the config in /config/install is never looked at again and that module config is handled in the config sync directory.

@DavMorr is correct in saying that module config should never include a UUID. I'd be surprised if the module actually installs correctly if it does.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment