Skip to content

Instantly share code, notes, and snippets.

@lincoln-chawora
Created June 30, 2021 15:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lincoln-chawora/b97b3e1ada6fbcfc8ac4a23b8b625317 to your computer and use it in GitHub Desktop.
Save lincoln-chawora/b97b3e1ada6fbcfc8ac4a23b8b625317 to your computer and use it in GitHub Desktop.
Drupal 8 How to update taxonomy url's alias in the database
use Drupal\Core\Database\Database;
/**
* Update tags url alias'.
*/
function YOUR_MODULE_NAME_update_8001() {
// "path_alias" is the name of the table being updated (this comes from the pathauto module)
// "alias" is the name of the field/column being updated.
// So whats happening here is that, we're updating the alias field/column on the path_alias table.
// The update being done is we're replacing the value of "//tags" with "/news-and-events/topics/".
Database::getConnection()
->update('path_alias')
->expression('alias', "REPLACE(alias, :old_value, :new_value)", [
':old_value' => '//tags/',
':new_value' => '/news-and-events/topics/',
])
->execute();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment