public function StyleDiscovery::isAllowedAccess

Checks whether the given account has access to the given style name.

Parameters

array $style_definition: The style definition.

\Drupal\Core\Session\AccountProxyInterface|null $account: (optional) The account to check access for. Defaults to current user.

Return value

bool TRUE if the user has access to the style. Otherwise, FALSE.

Overrides StyleDiscoveryInterface::isAllowedAccess

File

paragraphs_collection/src/StyleDiscovery.php, line 187

Class

StyleDiscovery
Provides common helper methods for style discovery. @todo Create documentation for style discovery https://www.drupal.org/node/2837995

Namespace

Drupal\paragraphs_collection

Code

public function isAllowedAccess(array $style_definition, AccountProxyInterface $account = NULL) {

  // The style does not define permission property. Allow access.
  if (empty($style_definition['permission']) || $style_definition['permission'] !== TRUE) {
    return TRUE;
  }
  $account = $account ?: $this->currentUser;
  $style_permission = 'use ' . $style_definition['name'] . ' style';

  // Check whether the user has a dedicated style permission.
  return $account
    ->hasPermission($style_permission);
}