You are here

public function LayoutParagraphsBuilderAccess::access in Layout Paragraphs 2.0.x

Parameters

\Drupal\Core\Session\AccountInterface $account: The account to check access for.

\Drupal\layout_paragraphs\LayoutParagraphsLayout $layout_paragraphs_layout: The layout paragraphs layout object.

string $operation: The operation being peformed (i.e. 'create' or 'delete').

string $component_uuid: The specific component being acted on.

\Drupal\paragraphs\ParagraphsTypeInterface $paragraph_type: The paragraph type of a component being added.

Return value

\Drupal\Core\Access\AccessResult The access result.

File

src/Access/LayoutParagraphsBuilderAccess.php, line 52

Class

LayoutParagraphsBuilderAccess
Class definition for LayoutParagraphsBuilderAccess.

Namespace

Drupal\layout_paragraphs\Access

Code

public function access(AccountInterface $account, LayoutParagraphsLayout $layout_paragraphs_layout, string $operation = NULL, string $component_uuid = NULL, ParagraphsTypeInterface $paragraph_type = NULL) {

  // Check field access.
  $access = $layout_paragraphs_layout
    ->getParagraphsReferenceField()
    ->access('edit', $account, TRUE);

  // Check access to host entity.
  $entity = $layout_paragraphs_layout
    ->getEntity();
  $lp_operation = $entity
    ->isNew() ? 'create' : 'update';
  $access = $access
    ->andIf($entity
    ->access($lp_operation, $account, TRUE));

  // Check access to specific paragraph entity.
  if ($component_uuid) {
    $paragraph = $layout_paragraphs_layout
      ->getComponentByUuid($component_uuid)
      ->getEntity();
    $access = $access
      ->andIf($paragraph
      ->access($operation, $account, TRUE));
  }

  // Check access to paragraph type.
  if ($paragraph_type) {
    $access_handler = $this->entityTypeManager
      ->getAccessControlHandler('paragraph');
    $access = $access
      ->andIf($access_handler
      ->createAccess($paragraph_type
      ->id(), $account, [], TRUE));
  }
  return $access;
}