Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

drupal 9 custom access checking for routes

<?php

namespace DrupalmymodAccess;

use DrupalCoreRoutingAccessAccessInterface;
use DrupalCoreAccessAccessResult;
use DrupalmymodStoreService;


class CardEditAccessChecker implements AccessInterface {
  // injected StoreService
  private $ss = NULL;
  
  public function __construct(StoreService $ss) {
    $this->ss = $ss;
  }
  
  public function access($product_id) {
    // marketplace manager can edit all...
    if ($this->ss->isMarketPlaceManager()) {
      return AccessResult::allowed();
    }
 
    // product owner can edit...
    if ($this->ss->ownsProduct($product_id)) {
      return AccessResult::allowed();
    }
    
    return AccessResult::forbidden();
  }
}
Source by gitlab.com #
 
PREVIOUS NEXT
Tagged: #drupal #custom #access #checking #routes
ADD COMMENT
Topic
Name
6+1 =