You are here

public function EditorNoteController::accessEditorNote in Editor Notes 8

Checks access to editor note.

Parameters

\Drupal\Core\Session\AccountInterface $account: Current user.

\Drupal\editor_note\Entity\EditorNote $editor_note: Editor note entity.

Return value

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

1 string reference to 'EditorNoteController::accessEditorNote'
editor_note.routing.yml in ./editor_note.routing.yml
editor_note.routing.yml

File

src/Controller/EditorNoteController.php, line 27

Class

EditorNoteController
Checks access for editor note routes.

Namespace

Drupal\editor_note\Controller

Code

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;
}