drupal 9 custom access checking for routes

Solutions on MaxInterview for drupal 9 custom access checking for routes by the best coders in the world

showing results for - "drupal 9 custom access checking for routes"
Isaac
22 Jun 2017
1<?php
2
3namespace Drupal\mymod\Access;
4
5use Drupal\Core\Routing\Access\AccessInterface;
6use Drupal\Core\Access\AccessResult;
7use Drupal\mymod\StoreService;
8
9
10class CardEditAccessChecker implements AccessInterface {
11  // injected StoreService
12  private $ss = NULL;
13  
14  public function __construct(StoreService $ss) {
15    $this->ss = $ss;
16  }
17  
18  public function access($product_id) {
19    // marketplace manager can edit all...
20    if ($this->ss->isMarketPlaceManager()) {
21      return AccessResult::allowed();
22    }
23 
24    // product owner can edit...
25    if ($this->ss->ownsProduct($product_id)) {
26      return AccessResult::allowed();
27    }
28    
29    return AccessResult::forbidden();
30  }
31}