Problem/Motivation
Whenever a value is present in the URL alias field while saving a node or its translation, ValidPathConstraintValidator calls $this->pathValidator->isValid($path). If the site uses any contrib or custom modules that implement hook_node_grants() then the access() method in NodeGrantDatabaseStorage queries the node_access table to check the access to determine if the path is valid or not. In the current logic, core uses the language code of the translation being saved in the db query. Now consider the following scenario
- Node has English as default language and is published.
- User tries to create a new translation.
In both cases, the node_access table is queried with the language code of the translation being saved to check the access. However, there won’t be any record for the unpublished translation, causing the validation to fail and resulting in the validation error “Either the path '%link_path' is invalid or you do not have access to it”.
Check comments #122 to #125 for more detailed analysis.
Steps to reproduce
- Install with demo_umami profile
- Give "Editorial workflow: Use Create New Draft transition" and "Article: Create new content" permissions to the editor role.
- Check the node_access table. There will be only one entry with nid 0 which is the default record.
- Create a custom module and implement hook_node_grants(). Install the module.
/**
* Implements hook_node_grants().
*/
function my_module_node_grants(AccountInterface $account, $operation) {
$grants = [];
return $grants;
}
- Login as admin and visit any admin page. There will be a message to rebuild the permissions. Click on Rebuild permissions to rebuild all permissions.
- Login with any of the editor accounts (Eg: uid=3) in incognito mode.
- Add an English article. Give a path in URL alias field and publish it.
- Try to add spanish translation.
Proposed resolution
There have been 3 suggested solutions based on where the problem is.
The problem is the node_access table. Option 1 is to modify the database by adding a "nid=0" record in node_access, #15.: But Node access table gets updated everytime permissions are rebuilt. So, not a robust solution.The problem is the alias field that is being defaulted to the original alias when creating a new translation. Leave that empty, #20 Reported to worķ. #21, #23, #24, #26, #27, #28, #46 and Reported to not work; #44, #45The problem is that Drupal\path\Plugin\Field\FieldWidget\PathWidget::validateFormElement() sets the form error even if the field is not accessible by user while it should not.#79. Reported to work #83, #85. But will not work if the alias field is visiblie in node edit form- Use fallback language in node_access query when the translation is new: #64, #122 to #125: Needs review
Note that In #30, the problem was not reproducible with core only. The suggestion is that access control modules are causing the problem. See #30, #31
Remaining tasks
Create a merge request - Done
Add tests - Done
Review MR 6210
Commit
User interface changes
API changes
Data model changes
N/A