You are here

class CourseAccessControlHandler in Course 3.x

Same name and namespace in other branches
  1. 8.3 src/Access/CourseAccessControlHandler.php \Drupal\course\Access\CourseAccessControlHandler
  2. 8.2 src/Access/CourseAccessControlHandler.php \Drupal\course\Access\CourseAccessControlHandler

Access controller for the Course entity.

Hierarchy

Expanded class hierarchy of CourseAccessControlHandler

File

src/Access/CourseAccessControlHandler.php, line 14

Namespace

Drupal\course\Access
View source
class CourseAccessControlHandler extends UncacheableEntityAccessControlHandler {

  /**
   * Handle multiple access denied messages (for enrolling and taking).
   *
   * {@inheritdoc}
   */
  protected function processAccessHookResults(array $access) {

    // @todo sort by weight and allow altering
    return parent::processAccessHookResults($access);
  }

  /**
   * Grant access to reports.
   *
   * {@inheritdoc}
   */
  protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
    if ($operation == 'report') {
      if ($account
        ->hasPermission('access all course reports')) {

        // If user has this permission then allow access without being able to
        // update.
        return AccessResultAllowed::allowed();
      }
      else {

        // Otherwise, check if the user can update this course.
        return parent::checkAccess($entity, 'update', $account);
      }
    }
    return parent::checkAccess($entity, $operation, $account);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CourseAccessControlHandler::checkAccess protected function Grant access to reports.
CourseAccessControlHandler::processAccessHookResults protected function Handle multiple access denied messages (for enrolling and taking).