Created
June 30, 2021 15:04
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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