From ccbac9473b0d3ff41f9edf734242429872f05abb Mon Sep 17 00:00:00 2001 From: naomi Date: Thu, 7 Jul 2022 17:20:10 +0100 Subject: [PATCH] broke something --- opencase.module | 30 ++++++++++++++------- src/Plugin/Block/AddActivity.php | 45 +++++++++++++++++++++++++++----- 2 files changed, 58 insertions(+), 17 deletions(-) diff --git a/opencase.module b/opencase.module index e84133a..5bd8a59 100644 --- a/opencase.module +++ b/opencase.module @@ -179,8 +179,8 @@ function opencase_entity_field_access($operation, \Drupal\Core\Field\FieldDefini /* Custom hook */ -function opencase_relevant_case_type_ids(string $actorTypeID):array { - switch ($actorTypeID) { +function opencase_relevant_case_type_ids(string $bundle):array { + switch ($bundle) { case 'client': return ['accommodation', 'asylum_support', 'employability', 'health', 'immigration', 'welfare_rights']; case 'volunteer': @@ -193,14 +193,24 @@ function opencase_relevant_case_type_ids(string $actorTypeID):array { /* Custom hook */ -function opencase_relevant_activity_type_ids(string $actorTypeID):array { - switch ($actorTypeID) { - case 'volunteer': - return ['email', 'phone_call', 'supervision']; - case 'client': - return ['email', 'lete', 'phone_call', 'case_note', 'destitution_funds_provided', 'research', 'application']; - case 'staff_member': - return ['application', 'interview']; +function opencase_relevant_activity_type_ids(string $entityType, string $bundle):array { + if ($entityType == 'oc_actor') { + switch ($bundle) { + case 'volunteer': + return ['email', 'phone_call', 'supervision', 'application', 'interview']; + case 'client': + return ['email', 'lete', 'phone_call', 'case_note', 'destitution_funds_provided', 'research', 'application']; + case 'staff_member': + return ['application', 'interview']; + } + } + if ($entityType == 'oc_case') { + switch ($bundle) { + case 'volunteer_engagement': + return ['email', 'phone_call', 'supervision', 'application', 'interview']; + default: + return ['email', 'lete', 'phone_call', 'case_note', 'destitution_funds_provided', 'research', 'application']; + } } return []; } diff --git a/src/Plugin/Block/AddActivity.php b/src/Plugin/Block/AddActivity.php index 84b7d0a..f7f81d8 100644 --- a/src/Plugin/Block/AddActivity.php +++ b/src/Plugin/Block/AddActivity.php @@ -3,12 +3,14 @@ namespace Drupal\opencase\Plugin\Block; use Drupal\Core\Block\BlockBase; +use Drupal\opencase_cases\Entity\OCCase; +use Drupal\opencase_entities\Entity\OCActor; /** * Provides a Block with some help text about actor type fields * * @Block( - * id = "add_activity", + * activity_type = "add_activity", * admin_label = @Translation("Add Activity"), * category = @Translation("Opencase"), * ) @@ -19,28 +21,57 @@ class AddActivity extends BlockBase { * {@inheritdoc} */ public function build():array { + if ($this->isOnACase()) { + return $this->makeBlockForAddingActivityToCase(); + } elseif ($this->isOnAnActor()) { + return $this->makeBlockForAddingActivityToActor(); + } + return ['#markup' => 'This block should only be placed on a case or on an actor.']; + } + + private function makeBlockForAddingActivityToCase():array { + $case = \Drupal::routeMatch()->getParameter('oc_case'); + $case_id = $case->id(); + $markup = ""; + return array('#markup' => $markup); + } + private function makeBlockForAddingActivityToActor():array { $actor = \Drupal::routeMatch()->getParameter('oc_actor'); $target_id = $actor->id(); - $actorType = $actor->bundle(); $markup = ""; return array('#markup' => $markup); } + private function isOnACase():bool { + return \Drupal::routeMatch()->getParameter('oc_case') instanceof OCCase; + } + + private function isOnAnActor():bool { + return \Drupal::routeMatch()->getParameter('oc_actor') instanceof OCActor; + } + + public function getCacheMaxAge():int { return 0; } - private function getActivityTypesToDisplay(string $actorType): array { + private function getActivityBundlesFor(string $entityType, string $bundle): array { // Client modules will provide a list of what activity types (bundles) are relevant for each actor type. // Check if they are implemented, and if so display them. $implemented_activity_types = \Drupal::service('entity_type.bundle.info')->getBundleInfo('oc_activity'); - $relevant_activity_type_ids = \Drupal::moduleHandler()->invokeAll('relevant_activity_type_ids', [$actorType]); + $relevant_activity_type_ids = \Drupal::moduleHandler()->invokeAll('relevant_activity_type_ids', [$entityType, $bundle]); $activity_types_to_display = []; foreach ($relevant_activity_type_ids as $type_id) { if (array_key_exists($type_id, $implemented_activity_types)) {