Using Drupal drush deploy hook
If you have followed my previous posts (Part 1, Part 2) regarding finding a workaround to programmatically create nodes at a destination site which is missing the node create configurations, this will be helpful for you.
This is not only specific for node creation, it can be for any scenario where a snippet of code needs to be executed after config-import.
drush deploy
command is available since drush 10.3 and it makes the deployment process much easier.
You only need to add a *.deploy.php
file and follow the hook naming convention as you would for hook update.
Code
In your custom module, create my_custom_module.deploy.php
file
/**
* My drush deploy hook example.
*/
function my_custom_module_deploy_0001_message() {
// ADD YOUR CUSTOM CODE HERE.
\Drupal::messenger()->addMessage('Deploy hook triggered');
}
Deployment
Once the code is done you can trigger your deployment along with all the configurations.
And you should see the deploy hook execute upon drush deploy
It’s that simple.
Resources
https://www.drush.org/latest/deploycommand/
https://www.hashbangcode.com/article/drupal-9-different-update-hooks-and-when-use-them