Drupal 9 Pro Tip - Using Drush to Work With System & File UUIDs

Submitted by slackstone on Tue, 11/23/2021 - 07:35

Back in the day of D7, UUID was not really a thing.  With D9 it's nice to understand what a UUID is and how to take advantage of it.  These are a few notes on the subject.

The UUID is a unique entity ID that can be and can be used across multiple systems.

A quick Example of why UUIDs are helpful:threethree
site_one.com/node/600 (page about cats)
site_two.com/node/600 (page about dogs)
site_three.com/UUID/29f176d2-b587-4f60-ae19-197f94348839(page about cats)
site_three.com/UUID/29f176d2-b737-4f60-ae19-197f943489e7(page about dogs)
With UUIDs, it's easier to share content between sites, without collisions. Node/600 would conflict between site_one and site _two.

# Use Drush to display the site's UUID
@ubuntu:/opt/www/gluebox.com/web$ ../vendor/drush/drush/drush config-get "system.alt="Sample Image" data-entity-type="file" data-entity-uuid="38000a34-fe4a-445d-b97e-9564be35a97d" src="/sites/default/files/inline-images/smooth_gluebox.png" site" uuid

# Use Drush to display the site's NAME
@ubuntu:/opt/www/gluebox.com/web$ ../vendor/drush/drush/drush config-get "system.site" name

# Use Drush to set the Sites UUID
@ubuntu:/opt/www/gluebox.com/web$ ../vendor/drush/drush/drush cset system.site uuid 29f176d2-b587-4f60-ae19-197f943489e7

The system UUID is neat and all, but what about File and Image UUIDs, and what is a Raw Image Path?
Here's an interesting thread on the topic: https://www.drupal.org/project/drupal/issues/2828048
(Allow tracking images added by URL from the file system)

Image files are tracked using data-entity-uuid and data-entity-type attributes, and those are only assigned when the file entity is saved"

( alt="Sample Image" data-entity-type="file" data-entity-uuid="38000a34-fe4a-445d-b97e-9564be35a97d" src="/sites/default/files/inline-images/smooth_gluebox.png" ) Sample Image