Access denied to layout in translated content when original not saved.

Created on 14 June 2023, over 1 year ago

Problem/Motivation

"You are not authorized to access this page." when accessing a translation layout when the original layout has not been edited/saved.

Steps to reproduce

- create some content in english (original language). save
- create translation (spanish). save
- Access layout tab in spanish translation.
- You get permission access denied.

The issue seems to be in handleTranslationAccess() (layout_builder_st/src/Plugin/SectionStorage/OverridesSectionStorage.php) function.
Specifically the "$this->isOverridden()" check which is false on content where original layout has not been saved.

isOverriden() function is from core layout_builder:

public function isOverridden() {
    // If there are any sections at all, including a blank one, this section
    // storage has been overridden. Do not use count() as it does not include
    // blank sections.
    return !empty($this->getSections());
  }

When original content hasn´t been saved "$this->getSections()" is empty array.

Just saving the original empty layout, without adding any content makes getSections() an array with one entry "\Drupal\layout_builder\Section", and thus passes the access check.

Proposed resolution

Seeems like simply removing the isOverridden() check in handleTranslationAccess() solves the issue, but might have unwanted effects.
If the original content layout indeed needs to be edited/saved first, at least there should be some message/warning as the "You are not authorized to access this page." message is extremely confusing as it´s got nothing to do with actual permissions.

💬 Support request
Status

Active

Component

Code

Created by

🇪🇸Spain tahiche

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

Comments & Activities

Production build 0.71.5 2024