Drush Tools for Inspecting Configuration

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 --help.
First up, if you need to figure out the machine name of a content type or see if a content type exists, try:

<br />
drush typeinfo-list<br />

This will list all the content types and entities on your site:
<br />
 item_instruction           item_instruction<br />
 item_instruction_type      -<br />
 language_content_settings  -<br />
 menu                       -<br />
 menu_link_content          -<br />
 node                       article<br />
 node                       page<br />
 node                       testlet<br />
 node                       testlet_item<br />
 taxonomy_term              tags<br />
 taxonomy_term              trajectories<br />
 taxonomy_vocabulary        -<br />
 user                       -<br />
 user_role                  -<br />
 view                       -<br />

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:
<br />
drush typeinfo article<br />

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:
<br />
drush typeinfo tags taxonomy_term<br />

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:
<br />
drush typeinfo-field field_tags article<br />

This will show us:
<br />
Field info for: field_tags<br />
Type: entity_reference<br />
Form displays:<br />
  - node.article.default<br />
Widgets (node.article):<br />
  default: entity_reference_autocomplete_tags<br />
Target type: taxonomy_term<br />
Target bundles: tags<br />
Cardinality: unlimited<br />

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:
<br />
drush typeinfo-field field_shared_topic event node<br />

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 --field-info, --display-info, and --widget-info flags.
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).

Taxonomy

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:

<br />
drush taxonomyinfo-vocab-list<br />

To list terms within the topic taxonomy:
<br />
drush taxonomyinfo-term-list topic<br />

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).

Migrate

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:

<br />
drush migrate-inspect-last Event<br />

Or even a random event we imported (useful when you want to spot check 30,000 nodes you imported!):
<br />
drush migrate-inspect-random Event<br />

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:
<br />
drush migrate-inspect-destination Event 100<br />

Or if you know the destination ID on the new site, but want to know the legacy ID from the old site:
<br />
drush migrate-inspect-source Event 200<br />

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:
<br />
drush migrate-inspect-find-source 200<br />
drush migrate-inspect-find-destination 100<br />

Drupal 8 note: this has not been updated for Drupal 8 yet.

Drupal Drupal 8 Drupal Planet

Read This Next