diff --git a/modules/opencase_cases/src/Form/OCCaseForm.php b/modules/opencase_cases/src/Form/OCCaseForm.php index 8e8a3ac..28448e7 100644 --- a/modules/opencase_cases/src/Form/OCCaseForm.php +++ b/modules/opencase_cases/src/Form/OCCaseForm.php @@ -36,7 +36,7 @@ class OCCaseForm extends ContentEntityForm { /** * {@inheritdoc} */ - public function save(array $form, FormStateInterface $form_state) { + public function save(array $form, FormStateInterface $form_state): void { $entity = $this->entity; $entity->setNewRevision(); $entity->setRevisionCreationTime(REQUEST_TIME); @@ -57,7 +57,7 @@ class OCCaseForm extends ContentEntityForm { ])); } // If you have unpublished the entity and you can't see unpublished entities, redirect to a more informative message than just "Access Denied". - if (!$form_state->getValue('status')['value'] && !\Drupal::currentUser()->hasPermission('view unpublished case entities')) { + if (!$this->isPublished($form_state) && !\Drupal::currentUser()->hasPermission('view unpublished case entities')) { \Drupal::messenger()->addMessage($this->t('The record for "%label" is now unpublished & hidden from you.', [ '%label' => $entity->label(), ])); @@ -67,4 +67,12 @@ class OCCaseForm extends ContentEntityForm { } } + private function isPublished(FormStateInterface $form_state): bool { + if (is_null($form_state->getValue('status'))) { + return false; // some entities have nothing set for the status in which case we want to treat them as published by default. + // TODO why don't they?? + } + return $form_state->getValue('status')['value']; + } + } diff --git a/opencase.module b/opencase.module index 7428471..e84133a 100644 --- a/opencase.module +++ b/opencase.module @@ -177,9 +177,23 @@ function opencase_entity_field_access($operation, \Drupal\Core\Field\FieldDefini } /* - Implementation of hook_relevant_activity_type_ids which is a custom hook invoked in the AddActivity block. + Custom hook */ -function opencase_relevant_activity_type_ids($actorTypeID) { +function opencase_relevant_case_type_ids(string $actorTypeID):array { + switch ($actorTypeID) { + case 'client': + return ['accommodation', 'asylum_support', 'employability', 'health', 'immigration', 'welfare_rights']; + case 'volunteer': + return ['volunteer_engagement']; + } + return []; +} + + +/* + Custom hook +*/ +function opencase_relevant_activity_type_ids(string $actorTypeID):array { switch ($actorTypeID) { case 'volunteer': return ['email', 'phone_call', 'supervision']; @@ -188,6 +202,7 @@ function opencase_relevant_activity_type_ids($actorTypeID) { case 'staff_member': return ['application', 'interview']; } + return []; } /** diff --git a/src/Plugin/Block/AddCase.php b/src/Plugin/Block/AddCase.php new file mode 100644 index 0000000..55b9782 --- /dev/null +++ b/src/Plugin/Block/AddCase.php @@ -0,0 +1,53 @@ +getParameter('oc_actor'); + $target_id = $actor->id(); + $actorType = $actor->bundle(); + $markup = ""; + return array('#markup' => $markup); + } + + public function getCacheMaxAge():int { + return 0; + } + + private function getCaseTypesToDisplay(string $actorType): array { + // Client modules will provide a list of what case types (bundles) are relevant for each actor type. + // Check if they are implemented, and if so display them. + $implemented_case_types = \Drupal::service('entity_type.bundle.info')->getBundleInfo('oc_case'); + $relevant_case_type_ids = \Drupal::moduleHandler()->invokeAll('relevant_case_type_ids', [$actorType]); + $case_types_to_display = []; + foreach ($relevant_case_type_ids as $type_id) { + if (array_key_exists($type_id, $implemented_case_types)) { + $case_types_to_display[$type_id] = $implemented_case_types[$type_id]; + } + } + return $case_types_to_display; + } +}