You are here

class UnFlagListsAccessCheck in Flag Lists 8

Same name and namespace in other branches
  1. 4.0.x src/Access/UnFlagListsAccessCheck.php \Drupal\flag_lists\Access\UnFlagListsAccessCheck

Provides routes with the ability to check access to the 'unflag' action.

Hierarchy

Expanded class hierarchy of UnFlagListsAccessCheck

1 string reference to 'UnFlagListsAccessCheck'
flag_lists.services.yml in ./flag_lists.services.yml
flag_lists.services.yml
1 service uses UnFlagListsAccessCheck
access_check.unflag_lists.action in ./flag_lists.services.yml
Drupal\flag_lists\Access\UnFlagListsAccessCheck

File

src/Access/UnFlagListsAccessCheck.php, line 16

Namespace

Drupal\flag_lists\Access
View source
class UnFlagListsAccessCheck implements AccessInterface {

  /**
   * The flag service.
   *
   * @var \Drupal\flag\FlagServiceInterface
   */
  protected $flagService;

  /**
   * Constructor.
   *
   * @param \Drupal\flag\FlagServiceInterface $flag_service
   *   The flag service.
   */
  public function __construct(FlagServiceInterface $flag_service) {
    $this->flagService = $flag_service;
  }

  /**
   * Checks access to the 'unflag' action.
   *
   * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
   *   The parametrized route.
   * @param \Drupal\flag\FlagInterface $flag
   *   The flag entity.
   * @param \Drupal\Core\Session\AccountInterface $account
   *   The user account.
   *
   * @return string
   *   A \Drupal\Core\Access\AccessInterface constant value.
   */
  public function access(RouteMatchInterface $route_match, FlagInterface $flag, AccountInterface $account) {
    $flaggable_id = $route_match
      ->getParameter('entity_id');
    $flaggable = $this->flagService
      ->getFlaggableById($flag, $flaggable_id);
    return $flag
      ->actionAccess('unflag', $account, $flaggable);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
UnFlagListsAccessCheck::$flagService protected property The flag service.
UnFlagListsAccessCheck::access public function Checks access to the 'unflag' action.
UnFlagListsAccessCheck::__construct public function Constructor.