You are here

public function YamlFormElementBase::checkAccessRules in YAML Form 8

Check element access (rules).

Parameters

string $operation: The operation access should be checked for. Usually "create", "update", or "view".

array $element: An element.

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

Return value

bool TRUE is the element can be accessed by the user.

Overrides YamlFormElementInterface::checkAccessRules

See also

\Drupal\yamlform\Entity\YamlForm::checkAccessRules

\Drupal\yamlform\Entity\YamlForm::checkAccessRule

1 call to YamlFormElementBase::checkAccessRules()
YamlFormElementBase::prepare in src/YamlFormElementBase.php
Prepare an element to be rendered within a form.

File

src/YamlFormElementBase.php, line 464

Class

YamlFormElementBase
Provides a base class for a form element.

Namespace

Drupal\yamlform

Code

public function checkAccessRules($operation, array $element, AccountInterface $account = NULL) {

  // Respect elements that already have their #access set to FALSE.
  if (isset($element['#access']) && $element['#access'] === FALSE) {
    return FALSE;
  }
  if (!$account) {
    $account = $this->currentUser;
  }
  if (!empty($element['#access_' . $operation . '_roles']) && !array_intersect($element['#access_' . $operation . '_roles'], $account
    ->getRoles())) {
    return FALSE;
  }
  elseif (!empty($element['#access_' . $operation . '_users']) && !in_array($account
    ->id(), $element['#access_' . $operation . '_users'])) {
    return FALSE;
  }
  return TRUE;
}