I am working on a custom module to specify the pathauto alias of a new node, based on taxonomy terms that a user sets when they create the node. For instance, for my
blog post content type, the alias would be auto-generated as
/blogs/this-is-a-new-blog-post. However, if the
category taxonomy is set to be
special-project, I want to change the alias to be
I'm able to load the node using
hook_entity_insert(). However, I haven't been able to figure out how to set the alias.
I've found examples of how to set the path when creating a new node, but I already have an existing node object in this hook. I've tried debugging the path from the entity using
$entity->toUrl()->getInternalPath(), but that just gives me the default URL (
/node/123), not the alias. Trying to debug
$node->path, I get an enormous
stdClass object that I can't really suss out. Trying to debug
drupal_set_message("alias: " . $node->path->alias);, I get this:
How can I see and alter the path alias on an existing node?