You are here

class EditorNoteController in Editor Notes 8

Checks access for editor note routes.

@package Drupal\editor_note\Controller

Hierarchy

Expanded class hierarchy of EditorNoteController

File

src/Controller/EditorNoteController.php, line 14

Namespace

Drupal\editor_note\Controller
View source
class EditorNoteController {

  /**
   * Checks access to editor note.
   *
   * @param \Drupal\Core\Session\AccountInterface $account
   *   Current user.
   * @param \Drupal\editor_note\Entity\EditorNote $editor_note
   *   Editor note entity.
   *
   * @return \Drupal\Core\Access\AccessResultInterface
   *   The access result.
   */
  public function accessEditorNote(AccountInterface $account, EditorNote $editor_note = NULL) {
    if (!empty($editor_note)) {
      $note_author = $editor_note->uid->entity;
      if (!empty($note_author) && $note_author
        ->id() == $account
        ->id()) {
        $access_result = AccessResult::allowed();
      }
      else {
        $access_result = AccessResult::allowedIf($account
          ->hasPermission('administer any editor note'));
      }
    }
    else {
      $access_result = AccessResult::forbidden();
    }
    return $access_result;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
EditorNoteController::accessEditorNote public function Checks access to editor note.