Skip to content
Snippets Groups Projects
Commit d95e8dee authored by Seth Hill's avatar Seth Hill
Browse files

Issue #3452591 by sethhill: Duplicate action is available to users without...

Issue #3452591 by sethhill: Duplicate action is available to users without permissions to create paragraphs.
parent c31037b2
No related branches found
No related tags found
1 merge request!169Toggle duplicate button based on user permission to create paragraph type.
Pipeline #192752 canceled
......@@ -278,7 +278,7 @@ class LayoutParagraphsBuilder extends RenderElement implements ContainerFactoryP
'#uuid' => $entity->uuid(),
'#layout_paragraphs_layout' => $this->layoutParagraphsLayout,
'#edit_access' => $this->editAccess($entity),
'#duplicate_access' => $this->createAccess() && $this->checkCardinality(),
'#duplicate_access' => $this->duplicateAccess($entity) && $this->checkCardinality(),
'#delete_access' => $this->deleteAccess($entity),
];
$build['#attached']['drupalSettings']['lpBuilder']['uiElements'][$entity->uuid()] = [];
......@@ -528,8 +528,8 @@ class LayoutParagraphsBuilder extends RenderElement implements ContainerFactoryP
/**
* Returns an AccessResult object.
*
* @return \Drupal\Core\Access\AccessResultInterface
* True if user can edit.
* @return bool
* True if user can create.
*/
protected function createAccess() {
$access = new AccessResultAllowed();
......@@ -539,6 +539,23 @@ class LayoutParagraphsBuilder extends RenderElement implements ContainerFactoryP
return $access->isAllowed();
}
/**
* Returns an AccessResult object.
*
* @param \Drupal\paragraphs\ParagraphInterface $paragraph
* The paragraph entity.
*
* @return bool
* True if user can duplicate.
*/
protected function duplicateAccess(ParagraphInterface $paragraph) {
if ($this->isTranslating() && !($this->supportsAsymmetricTranslations())) {
$access = new AccessResultForbidden('Cannot duplicate paragraphs while in translation mode.');
return $access->isAllowed();
}
return $paragraph->access('create');
}
/**
* Returns TRUE if in translation context.
*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment