Add a simple access handler for plan_record entities that checks plan entity access.
This commit is contained in:
parent
8bf87f00fe
commit
a79a2989a8
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\plan\Access;
|
||||
|
||||
use Drupal\Core\Access\AccessResult;
|
||||
use Drupal\Core\Entity\EntityAccessControlHandler;
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
|
||||
/**
|
||||
* Defines plan_record access logic.
|
||||
*/
|
||||
class PlanRecordAccess extends EntityAccessControlHandler {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
|
||||
|
||||
// If a plan is referenced, access is based on access to the plan.
|
||||
/** @var \Drupal\plan\Entity\PlanInterface[] $plans */
|
||||
$plans = $entity->get('plan')->referencedEntities();
|
||||
if (!empty($plans[0])) {
|
||||
return AccessResult::allowedIf($plans[0]->access($operation, $account));
|
||||
}
|
||||
|
||||
// Otherwise, delegate to the parent method.
|
||||
return parent::checkAccess($entity, $operation, $account);
|
||||
}
|
||||
|
||||
}
|
|
@ -23,6 +23,9 @@ use Drupal\Core\Field\BaseFieldDefinition;
|
|||
* singular = "@count plan record relationship",
|
||||
* plural = "@count plan record relationships",
|
||||
* ),
|
||||
* handlers = {
|
||||
* "access" = "Drupal\plan\Access\PlanRecordAccess",
|
||||
* },
|
||||
* base_table = "plan_record",
|
||||
* data_table = "plan_record_data",
|
||||
* entity_keys = {
|
||||
|
|
Loading…
Reference in New Issue