Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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