Recently I had to generate term-specific aliases (aliases that are different from the default alias pattern set for Article entities). This is how to do it:
1. Enable the Pathauto module
2. Set the default URL alias pattern for your content type in order to fire the hook
3. Implement hook_pathauto_alias_alter() in your .module file.
Example module structure:
mymodule/
– mymodule.info.yml
– mymodule.module
– src/
– ArticlePathAlias.php
I like to keep .module clean and simple and because of that I store the main logic in src/ArticlePathAlias.php file.
The mymodule.info.yml this is just a regular .info file.
4. Add the following to your mymodule.module file:
Source: New feed