You are here

public static function WebformUiAccess::checkWebformElementAccess in Webform 6.x

Same name and namespace in other branches
  1. 8.5 modules/webform_ui/src/Access/WebformUiAccess.php \Drupal\webform_ui\Access\WebformUiAccess::checkWebformElementAccess()

Check that webform element type can be added by a user.

Parameters

\Drupal\webform\WebformInterface $webform: A webform.

string $type: An element type.

\Drupal\Core\Session\AccountInterface $account: Run access checks for this account.

Return value

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

2 string references to 'WebformUiAccess::checkWebformElementAccess'
webform_cards.routing.yml in modules/webform_cards/webform_cards.routing.yml
modules/webform_cards/webform_cards.routing.yml
webform_ui.routing.yml in modules/webform_ui/webform_ui.routing.yml
modules/webform_ui/webform_ui.routing.yml

File

modules/webform_ui/src/Access/WebformUiAccess.php, line 75

Class

WebformUiAccess
Defines the custom access control handler for the webform UI.

Namespace

Drupal\webform_ui\Access

Code

public static function checkWebformElementAccess(WebformInterface $webform, $type, AccountInterface $account) {

  /** @var \Drupal\webform\Plugin\WebformElementManagerInterface $element_manager */
  $element_manager = \Drupal::service('plugin.manager.webform.element');
  $access = $webform
    ->access('update', $account, TRUE);
  $access = $access
    ->andIf(!$element_manager
    ->isExcluded($type) ? AccessResult::allowed() : AccessResult::forbidden());
  $access
    ->addCacheableDependency($webform);
  $access
    ->addCacheableDependency(\Drupal::config('webform.settings'));
  return $access;
}