Unavailable to add/edit paragraphs on adding translation form while use modules which use hook_node_access_records

Created on 22 November 2017, about 7 years ago
Updated 19 August 2024, 6 months ago

Problem/Motivation

When we use translations and modules which use hook_node_access_records we can't add/edit paragraphs on adding translation form for node by some roles. It affects to roles, which doesn't have permission "edit any/own %content_type% content", but have allowable record in node_access table.

Let's imagine we have created news in English language. So we have allowable record in node_access table for english version. And now we are adding French translation.

In this case we have next access to logic for paragraph widget on adding translation form:
1. Check access on paragraph.
2. \Drupal\paragraphs\ParagraphAccessControlHandler::checkAccess fallbacks to access for parent entity.
3. Check access on parent entity.
4. \Drupal\Core\Entity\EntityAccessControlHandler::access invokes entity_access and node_access hooks, which result AccessResultNeutral result.
5. Because we have neutral access \Drupal\node\NodeAccessControlHandler::checkAccess invokes grantStorage access.
6. \Drupal\node\NodeGrantDatabaseStorage::access check records for French node, which in fact not saved yet.

So on the one hand we have allowable permission in node_access table for English language, but on the other hand we have prepared and filled entity with french fields, but in fact not saved yet. So we have message "You are not allowed to edit or remove this Paragraph", but we must have required access.

Proposed resolution

It have investigated this issue and I can propose solution to provide identical solution as we have on creating new node. While we create new node, method \Drupal\paragraphs\Entity\Paragraph::getParentEntity returns NULL. So I offer to modify this method for returning NULL if we have no saved trasnlation for entity.

I will apply patch in comments.

πŸ› Bug report
Status

Needs review

Version

1.0

Component

Code

Created by

πŸ‡·πŸ‡ΊRussia kalistos

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024