You are here

private function VotingApiReactionForm::checkAccess in Voting API Reaction 8

Check if current user has access to this form.

Parameters

\Drupal\Core\Form\FormStateInterface $form_state: The form state.

mixed $modify: Vote entity is beign modified.

Return value

mixed Null if user any access. Boolean if user can create or modify.

1 call to VotingApiReactionForm::checkAccess()
VotingApiReactionForm::buildForm in src/Form/VotingApiReactionForm.php
Form constructor.

File

src/Form/VotingApiReactionForm.php, line 305

Class

VotingApiReactionForm
Form implementation of the reaction form used in field formatter.

Namespace

Drupal\votingapi_reaction\Form

Code

private function checkAccess(FormStateInterface $form_state, $modify = FALSE) {
  $items = $form_state
    ->get('field_items');
  $instance = implode(':', [
    $items
      ->getEntity()
      ->getEntityTypeId(),
    $items
      ->getEntity()
      ->bundle(),
    $items
      ->getName(),
  ]);
  if (!$this->currentUser
    ->hasPermission('view reactions on ' . $instance)) {
    return NULL;
  }
  return $this->currentUser
    ->hasPermission($modify ? 'modify reaction on ' . $instance : 'create reaction on ' . $instance);
}