LayoutParagraphsBuilderAccess.php in Layout Paragraphs 2.0.x
File
src/Access/LayoutParagraphsBuilderAccess.php
View source
<?php
namespace Drupal\layout_paragraphs\Access;
use Drupal\Core\Session\AccountInterface;
use Drupal\paragraphs\ParagraphsTypeInterface;
use Drupal\Core\Routing\Access\AccessInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\layout_paragraphs\LayoutParagraphsLayout;
class LayoutParagraphsBuilderAccess implements AccessInterface {
protected $entityTypeManager;
public function __construct(EntityTypeManagerInterface $entity_type_manager) {
$this->entityTypeManager = $entity_type_manager;
}
public function access(AccountInterface $account, LayoutParagraphsLayout $layout_paragraphs_layout, string $operation = NULL, string $component_uuid = NULL, ParagraphsTypeInterface $paragraph_type = NULL) {
$access = $layout_paragraphs_layout
->getParagraphsReferenceField()
->access('edit', $account, TRUE);
$entity = $layout_paragraphs_layout
->getEntity();
$lp_operation = $entity
->isNew() ? 'create' : 'update';
$access = $access
->andIf($entity
->access($lp_operation, $account, TRUE));
if ($component_uuid) {
$paragraph = $layout_paragraphs_layout
->getComponentByUuid($component_uuid)
->getEntity();
$access = $access
->andIf($paragraph
->access($operation, $account, TRUE));
}
if ($paragraph_type) {
$access_handler = $this->entityTypeManager
->getAccessControlHandler('paragraph');
$access = $access
->andIf($access_handler
->createAccess($paragraph_type
->id(), $account, [], TRUE));
}
return $access;
}
}