When an entity is created via a JSON API POST route, the returned response contains empty path values. You need to do a new GET request to retrieve the correct path values.
Issue fork pathauto-3223746
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
cgoffin commentedI created a fix that sets the generated path onto the entity.
Comment #4
cgoffin commentedComment #5
bramdriesenComment #6
berdirI could be wrong, but setting the path like that I think overwrites the pathauto flag. The return value documentation around these methods is messy, but it passes through from \Drupal\pathauto\AliasStorageHelper::save(), which kinda matches the path item values, but also not fully (there is no source, for example). Maybe we should set the values explicitly, with $entity->get('path')->alias = $result['alias'] and so on?
Comment #8
mably commentedUpdated the MR to reset the path field computed value instead.
Any feedback welcome.
Comment #9
mably commentedComment #10
mably commentedSummary
After Pathauto generates or updates an alias, the entity's in-memory
pathfield still returnsNULLor the old alias value, causing JSON:API (and other serializers) to return stale/empty path data in responses.Problem
Drupal's
pathfield on content entities is a computed field — its value is lazily loaded from the database and then cached in memory for the lifetime of the entity object. When Pathauto generates a new alias duringentity->save(), the alias is written to the database but the entity's computed path field still holds the previously cached value. Any code that reads$entity->path->aliasafter save (e.g. JSON:API serializing the entity in a POST/PATCH response) getsNULLor the old alias instead of the freshly generated one.Changes
resetComputedValue()method that clears the internal item list and resets thevalueComputedflag, forcing the field to re-read from the database on next access.createEntityAlias()returns a non-null result (meaning an alias was created or updated),resetComputedValue()is called on the entity'spathfield so the in-memory representation stays in sync.testResetComputedValueRefreshesAlias()verifies that after an external alias change, callingresetComputedValue()causes the field to return the updated alias;testPathFieldUpdatedAfterAliasGeneration()verifies that after a node title change and save, the path field automatically reflects the new alias without manual intervention.