finished entity type relations

This commit is contained in:
naomi
2018-06-13 17:51:14 +02:00
parent fd1a0d5156
commit d46142ee2b
3 changed files with 30 additions and 37 deletions

View File

@ -13,29 +13,13 @@ class EntityTypeRelations {
$base_field_override = \Drupal\Core\Field\Entity\BaseFieldOverride::load("oc_case.$case_type.actors_involved");
$allowedActorTypes = array();
if ($base_field_override) {
$targetBundleConfig = $base_field_override->getSettings()['handler_settings']['target_bundles'];
if ($targetBundleConfig) {
// example of $targetBundleConfig: ['client' => 'client', 'volunteer' => 0]
foreach($targetBundleConfig as $machine_name => $value) {
if ($value) {
$allowedActorTypes[] = $machine_name;
}
}
}
$allowedActorTypes = $base_field_override->getSettings()['handler_settings']['target_bundles'];
}
return $allowedActorTypes; // NB. this is an array of machine names only, indexed numerically.
return $allowedActorTypes; // // format: ['volunteer' => 0, 'client' => 'client']
}
public static function getAllowedCaseTypesForActorType($actor_type) {
$allCaseTypes = \Drupal::service('entity_type.bundle.info')->getBundleInfo('oc_case');
// $allCaseTypes is array where the key is the machine name and the value is array containing label
$allowedCaseTypes = array();
foreach(array_keys($allCaseTypes) as $caseType) {
if (in_array($actor_type, self::getAllowedActorTypesForCaseType($caseType))) {
$allowedCaseTypes[$caseType] = $allCaseTypes[$caseType]['label'];
}
}
return $allowedCaseTypes; // NB. this is an array of labels, indexed by machine name.
}
public static function getAllowedActivityTypesForCaseType($case_type) {
$caseTypeConfig = \Drupal::entityTypeManager()->getStorage('oc_case_type')->load($case_type);
return $caseTypeConfig->get('allowedActivityTypes'); // format: ['application' => 'application', 'interview' => 0]
}
}