You are here

WebformSourceEntityAccess.php in Webform 6.x

Same filename and directory in other branches
  1. 8.5 src/Access/WebformSourceEntityAccess.php

File

src/Access/WebformSourceEntityAccess.php
View source
<?php

namespace Drupal\webform\Access;

use Drupal\Core\Access\AccessResult;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Session\AccountInterface;

/**
 * Defines the custom access control handler for the webform source entities.
 */
class WebformSourceEntityAccess {

  /**
   * Check whether the user can access an entity's webform results.
   *
   * @param \Drupal\Core\Entity\EntityInterface $entity
   *   An entity.
   * @param \Drupal\Core\Session\AccountInterface $account
   *   Run access checks for this account.
   *
   * @return \Drupal\Core\Access\AccessResultInterface
   *   The access result.
   */
  public static function checkEntityResultsAccess(EntityInterface $entity, AccountInterface $account) {

    /** @var \Drupal\webform\WebformEntityReferenceManagerInterface $entity_reference_manager */
    $entity_reference_manager = \Drupal::service('webform.entity_reference_manager');
    $access = $entity
      ->access('update', $account, TRUE);
    $access
      ->andIf(AccessResult::allowedIf($entity_reference_manager
      ->getWebform($entity)));
    return $access;
  }

}

Classes

Namesort descending Description
WebformSourceEntityAccess Defines the custom access control handler for the webform source entities.