Drupal 9 Custom Access Checking For Routes

[Solved] Drupal 9 Custom Access Checking For Routes | Php Frameworks Drupal - Code Explorer | yomemimo.com
Question : drupal 9 custom access checking for routes

Answered by : dave-oukrqevg8554

<?php
namespace Drupal\mymod\Access;
use Drupal\Core\Routing\Access\AccessInterface;
use Drupal\Core\Access\AccessResult;
use Drupal\mymod\StoreService;
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 : https://gitlab.com/-/snippets/1945414 | Last Update : Wed, 16 Jun 21

Answers related to drupal 9 custom access checking for routes

Code Explorer Popular Question For Php Frameworks Drupal