How to change a content type’s machine name in Drupal 8

With Drupal Console and Drupal 8’s Configuration Management

Phil Wolstenholme
1 min readJan 30, 2016

Note that this advice no longer works and is out of date. You can change the machine names of config items that you have just created by using find and replace tools (sed, rename, etc) but you’ll have a harder time if any content exists.

I recently had to rename a content type’s machine name after I used the wrong format which would have caused inconsistency in how the various content types on my site were named. Luckily, it’s easy enough to change a machine name using Drupal Console and the Configuration Management tools built into Drupal 8.

Run this to export your site’s configuration to your configuration sync directory (it will end up somewhere with a path like sites/default/files/config_Iz4K9eLC5r…JEPq1K5KAc/sync):

drupal config:export

In something like PhpStorm or the command line, do a search and replace across the whole sync directory, swapping instances of your old_content_type machine name for your new_content_type machine name. This will update the contents of the config files, but their filenames will still need changing.

To change the filenames, use the terminal to cd to the config sync directory, and run the following command:

rename 's/old_content_type/new_content_type/g' ./*

That will update the filenames of the config files. Finally, update your site’s database by runing this Drupal Console command:

drupal config:import

You should now see the new content type machine name is in use. If there are any issues, try rebuilding your cache:

drupal cache:rebuild

--

--

Phil Wolstenholme

I’m an accomplished developer with a wide range of skills, knowledge, and experience, particularly focussed on accessibility and frontend web performance.