Migrate from drush_cmi_tools for Drupal 9
The fact that Drupal is constantly being updated and improved is great. There is one caveat, you also need to be in shape and follow the latest updates. To compete in the Drupal business, you need to explore new tools and opportunities. One of such is drush_cmi_tools. Keep following our mini-guide on migrating from drush_cmi_tools for Drupal 9 to become the best specialist in this field. Our team always invites you to make a cup of magical espresso or delicious tea and check out a super-useful article. This guidance will be short but technical and valuable for anyone involved in custom Drupal development. Just contact us in any way convenient for you to get advice or assistance.
What is Drupal Drush?
It was last updated on 7 February 2019.
- Installation process:
composer require "drupal/drush_cmi_tools:~2.0"
The official description of Drush CMI Tool says:
"Provides advanced CMI import and export functionality for CMI workflows."
We want to add that recently Drush CMI was a command-line tool actively used to work locally or remotely with a Drupal site. But almost simultaneously, with the Drupal 9 release, such a tool as Drush was deprecated. It has been replaced by an even more powerful and feature-rich Config Ignore 3 tool.
What is Config Ignore 3?
It was last updated on 15 July 2021.
The official description of Config Ignore 3 says:
"Ever experienced that your site's configuration was overridden, by the configuration on the file system, when running a drush cim? Not anymore! This module is a tool to let you keep the configuration you want, in place."
Note! Config Ignore 3 requires Config Filter, which needs Drush since 8.1.10.
What's new? Config Ignore 3 now uses the new APIs for Drupal 8.8 and above. Previously, the dependency on config_filter was removed from it. This module can be called a new generation module. It can completely replace Drush CMI Tools for you. The module has even better integration with core APIs'. In addition, Config Ignore finally got rid of the annoying pesky leftover field maps that have spoiled the nerves of more than one developer.
3 Steps to migrate from drush_cmi_tools for Drupal 9
Step #1 Upgrade the path
First of all, the migration must be started with a path upgrade. We think this will not be difficult for you to do because it is pretty simple. It requires the Config Ignore 3. x version. Don't forget to apply a patch from this issue. Call the following in the composer.json patches:
"drupal/config_ignore": { "fixes import (3117694)": "https://www.drupal.org/files/issues/2020-05-28/3117694-active-config-25.patch" },
And next:composer require drupal/config_ignore:^3
And only after these commands you can enable config_ignore and disable drush_cmi_tools:drush en config_ignore -y drush pmu drush_cmi_tools -y
Config Ignore 3 tool requires Drush 10. If you are using earlier versions, you should upgrade this via Composer.composer require drush/drush:^10
Step #2 Migrate ignored config settings
Now let's move on to the next important step - migrate all ignored config settings into config_ignore settings. It would be best to upgrade the path manually to migrate your ignored config settings. This is because enabling the module and changes to the module's config happen simultaneously. This means that all ignored config will be deleted if there is no updated import hook. Move the yml file, which contains all ignored config for drush_cmi_tools, to config_ignore.settings.yml. In our case, this is in drush/config-ignore.yml. We use the following command:mv drush/config-ignore.yml YOUR_CONFIG_SYNC_DIRECTORY/config_ignore.settings.yml
After, change the key status from ignore to ignored_config_entities
In the end, it should look like this:
ignored_config_entities: - devel.settings - devel.toolbar.settings
Ultimately, you can add an updated hook to the module. Roughly it should look like this:
/** * Migrate to config_ignore. * * For this to work, updb needs to be before config-import in your deployment. * Alternatively, use `drush deploy`. */ function MY_MODULE_update_N() { /** @var \Drupal\Core\Extension\ModuleInstallerInterface $moduleInstaller */ $moduleInstaller = \Drupal::service('module_installer'); $moduleInstaller->install([ 'config_ignore', ], FALSE); // Populate config_ignore initial values so we don't delete configs we need // in the first config import step after this. $syncDirectory = Settings::get('config_sync_directory'); $data = Yaml::decode(file_get_contents(sprintf('%s/config_ignore.settings.yml', $syncDirectory))); \Drupal::configFactory()->getEditable('config_ignore.settings')->setData($data)->save(); }
Step #3 Update the deployment scripts
Here we finally got to the last step. After the migration, you need to change the commands that you used in the deployment scripts. Try running Makefile commands to run update-db, config-import, and cache-clear. Forget about using Drush commands from now on, change them to:
We highly recommend using the Drush Deploy command. This will help you run hooks after deployment. It will be especially useful for those who plan to create and launch a new taxonomy vocabulary or add default terms when deployed. To do this, add the following:
my_module.deploy.php /** * Add some terms. */ function MY_MODULE_deploy_add_terms() { $terms = ['Foo', 'Bar', 'Baz']; foreach ($terms as $term) { $term = Term::create(['name' => $term, 'vid' => 'new_vocab']); $term->save(); } }
Well, that's it. Congratulation, you have done it. The Golems team hopes that the information was useful to you!
Migrate from drush_cmi_tools for Drupal 9 with the Golems web development agency!
The Config Ignore module is what replaced the Drupal Drush tool. It's great if you want to add config patterns to ignore or migrate from drush_cmi_tools for Drupal. We appreciated this solution for its power and flexibility. Honestly, you will have to learn a lot to work with this. This quick Drupal guide on migration from drush_cmi_tools for Drupal 9 is a good example that can help you. We hope that all the information is relevant to you. If you have any questions or concerns about migrating from Drush, we'd love to hear from you. Visit our Drupal services pages to get expert help from the Golems team.