I have a confession to make: I don't like clicking through the Drupal admin. Over the course of a project, beit one with content migrations, configuration in code, or just general site building, the information I need the most is field and taxonomy configuration. Typically, this means bouncing betweens tabs for content types and taxonomies which consumes time and precious clicks. Add in custom entities in our new Drupal 8 projects and there's even more time spent in the admin.
After a few dozen repetitions of navigating between field and taxonomy screens, I was ready to build tools to make the pain points of this process go away. I’d like to introduce you to Drush TypeInfo, Drush TaxonomyInfo, and Migrate Inspect. Hopefully, you find these tools helpful in working on your projects. Besides helping with the initial setup of a project, I feel like these tools are excellent when you're dropped into a project later in the process. Even for project with a detailed architectural plan, things change, documentation goes stale, and the only real source of truth is the actual site being built.
Content Types and Entities
Born from the fire of massive migrations, Drush TypeInfo is a Drush command that can provide you with all the information you could want about your content types and entities. The examples below show the full command names, but everything also has short aliases which you can find by running drush
First up, if you need to figure out the machine name of a content type or see if a content type exists, try:
This will list all the content types and entities on your site:
item_instruction item_instruction item_instruction_type - language_content_settings - menu - menu_link_content - node article node page node testlet node testlet_item taxonomy_term tags taxonomy_term trajectories taxonomy_vocabulary - user - user_role - view -
Pro tip for the list: if you only want a specific entity type, you can specify that as well:
drush typeinfo-list node. Next, maybe you need to check out the fields on an article content type:
drush typeinfo article
If you're looking for information about the fields on an entity besides nodes, you can look that up too. For fields on a taxonomy term the command would be:
drush typeinfo tags taxonomy_term
Now we're in business, but what about even more information? Well,
field_tags probably relates to a taxonomy, but let's make sure we know exactly which one:
drush typeinfo-field field_tags article
This will show us:
Field info for: field_tags Type: entity_reference Form displays: - node.article.default Widgets (node.article): default: entity_reference_autocomplete_tags Target type: taxonomy_term Target bundles: tags Cardinality: unlimited
We can see that the field is targeting the topic taxonomy and that it accepts unlimited values. If you want to see field instance info (like field widget settings), you can also pass the bundle/entity type:
drush typeinfo-field field_shared_topic event node
This example will show the
field_shared_topic information as it relates to the
event content type (I'm specifying the
node entity type here, but Drush TypeInfo will also make this assumption for you by default if you want to be lazy).
If you want to see raw internal arrays that Drupal uses for a field, you can get extra in-depth details with the
Drupal 8 note: this is mostly up-to-date with Drupal 8 functionality, but there are likely more things to load (including some of the display and form display information).
Next up: taxonomies. It's common to have several vocabularies complete with their own terms. Accessing a list of vocabularies and their terms used to mean plenty of clicking and tabbing through the UI. Not anymore -- I created Drush TaxonomyInfo to display site-wide taxonomy information with a single command.
To list out the vocabularies on a site:
To list terms within the topic taxonomy:
drush taxonomyinfo-term-list topic
Drupal 8 note: this should be updated and ready to go for Drupal 8 with the exception of nested terms, these will not show up as nested (yet).
Several Drupal 7 projects I worked on last year included very large content migrations. The Migrate module has command line tools for core functionality (importing, rolling back, etc.) but what happens with the data once it is imported? Let's check it out with the help of a tool called Migrate Inspect.
If we've imported some legacy events with an Event migration, we may want to open the last node we imported in a browser:
drush migrate-inspect-last Event
Or even a random event we imported (useful when you want to spot check 30,000 nodes you imported!):
drush migrate-inspect-random Event
When you're reviewing your migration, you may notice a source node that didn't get pulled into the destination correctly. In a case where you know the source ID, but you don't know where that content ended up on the new site, you can find that with the command:
drush migrate-inspect-destination Event 100
Or if you know the destination ID on the new site, but want to know the legacy ID from the old site:
drush migrate-inspect-source Event 200
Sometimes you might know a source or destination ID but unsure which migration it came from. This usually happens for me in cases where there are multiple migrations that can put content into a destination node (for example, when the old site has blog posts and news, but they're being combined on the new site). Migrate Inspect comes with two commands to make this easier by searching for you. Again the commands are broken up into source or destination versions, depending on the ID you have at hand:
drush migrate-inspect-find-source 200 drush migrate-inspect-find-destination 100
Drupal 8 note: this has not been updated for Drupal 8 yet.