You are here

public static function ParagraphsLockablePlugin::determineParagraphAccess in Paragraphs Collection 8

Check the access for the paragraph based on the lockable setting.

Only add content access controls if: Not a view operation Lockable Behavior is enabled Lockable has the locked value set as true.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The paragraph entity.

string $operation: The current operation.

\Drupal\Core\Session\AccountInterface $account: The current logged in user.

Return value

\Drupal\Core\Access\AccessResult The access result, will be false if the paragraph is locked and the user does not have the appropriate permission.

1 call to ParagraphsLockablePlugin::determineParagraphAccess()
paragraphs_collection_paragraph_access in ./paragraphs_collection.module
Implements hook_ENTITY_TYPE_access().

File

src/Plugin/paragraphs/Behavior/ParagraphsLockablePlugin.php, line 105

Class

ParagraphsLockablePlugin
Provides a Paragraphs Lockable plugin.

Namespace

Drupal\paragraphs_collection\Plugin\paragraphs\Behavior

Code

public static function determineParagraphAccess(EntityInterface $entity, $operation, AccountInterface $account) {

  /** @var ParagraphsType $paragraphs_type */
  $paragraphs_type = $entity
    ->getParagraphType();
  if ($operation !== 'view' && $entity
    ->getBehaviorSetting('lockable', 'locked') && $paragraphs_type
    ->hasEnabledBehaviorPlugin('lockable')) {
    $accessResult = AccessResult::forbiddenIf(!$account
      ->hasPermission('administer lockable paragraph'));
  }
  else {
    $accessResult = AccessResult::neutral();
  }
  $accessResult
    ->addCacheableDependency($entity);
  $accessResult
    ->addCacheableDependency($paragraphs_type);
  return $accessResult;
}