Added function to cases for getting case provider ids

This commit is contained in:
2022-06-14 13:55:25 +01:00
parent 2c65aff7e1
commit 49bf43e5b4
2 changed files with 117 additions and 8 deletions

View File

@ -9,7 +9,6 @@ use Drupal\Core\Entity\RevisionableContentEntityBase;
use Drupal\Core\Entity\RevisionableInterface;
use Drupal\Core\Entity\EntityChangedTrait;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\EntityTypeManager;
use Drupal\user\UserInterface;
/**
@ -85,6 +84,10 @@ class OCCase extends RevisionableContentEntityBase implements OCCaseInterface
/**
* {@inheritdoc}
*/
public static function loadFromUrlQueryParameter(string $param) {
return self::load(\Drupal::request()->query->get($param));
}
public static function preCreate(EntityStorageInterface $storage_controller, array &$values)
{
parent::preCreate($storage_controller, $values);
@ -93,7 +96,21 @@ class OCCase extends RevisionableContentEntityBase implements OCCaseInterface
];
}
public function getCaseProvisionIds(EntityTypeManager $etm): array {
public function getCaseProviderIds(int $role_id = null): array {
$case_provision_ids = $this->getCaseProvisionIds();
$provider_ids = [];
foreach($case_provision_ids as $id) {
$provision = \Drupal::entityTypeManager()->getStorage('oc_case_provision')->load($id);
if ($provision instanceOf OCCaseProvision) {
if (is_null($role_id) || $role_id == $provision->get('oc_case_provider_role')->target_id) {
$provider_ids[] = $provision->get('oc_provider')->target_id;
}
}
}
return $provider_ids;
}
private function getCaseProvisionIds(): array {
$query = \Drupal::entityTypeManager()->getStorage('oc_case_provision')->getQuery();
$query->condition('oc_case.target_id', $this->id());
return $query->execute();