Add PlanRecordInterface::getPlan()
This commit is contained in:
parent
bd091b7d39
commit
06b930886a
|
@ -18,10 +18,9 @@ class PlanRecordAccess extends EntityAccessControlHandler {
|
|||
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));
|
||||
/** @var \Drupal\plan\Entity\PlanRecordInterface $plan */
|
||||
if ($plan = $entity->getPlan()) {
|
||||
return AccessResult::allowedIf($plan->access($operation, $account));
|
||||
}
|
||||
|
||||
// Otherwise, delegate to the parent method.
|
||||
|
|
|
@ -82,4 +82,11 @@ class PlanRecord extends ContentEntityBase implements PlanRecordInterface {
|
|||
return $fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getPlan(): ?PlanInterface {
|
||||
return $this->get('plan')->first()?->entity;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -17,4 +17,12 @@ interface PlanRecordInterface extends ContentEntityInterface {
|
|||
*/
|
||||
public function getBundleLabel();
|
||||
|
||||
/**
|
||||
* Returns the Plan entity the plan record is assigned to.
|
||||
*
|
||||
* @return \Drupal\plan\Entity\PlanInterface|null
|
||||
* The plant entity or NULL if not assigned.
|
||||
*/
|
||||
public function getPlan(): ?PlanInterface;
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue