From 80f42c7bf30aec7c485c6e8929b66b132df9f4b9 Mon Sep 17 00:00:00 2001 From: naomi Date: Tue, 8 May 2018 13:21:12 +0200 Subject: [PATCH] Added case list link to add-new-case page --- .../opencase_entities/src/Entity/OCCase.php | 2 +- opencase.module | 9 ++++-- src/Plugin/Block/ContextualMenu.php | 32 +++++++++++++++++++ 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/modules/opencase_entities/src/Entity/OCCase.php b/modules/opencase_entities/src/Entity/OCCase.php index 310e823..0d19cfe 100644 --- a/modules/opencase_entities/src/Entity/OCCase.php +++ b/modules/opencase_entities/src/Entity/OCCase.php @@ -79,7 +79,7 @@ class OCCase extends RevisionableContentEntityBase implements OCCaseInterface { * id from the URL. */ public static function defaultVal() { - return \Drupal::request()->query->get('actor_id');; + return \Drupal::request()->query->get('actor_id'); } /** diff --git a/opencase.module b/opencase.module index bc2ae36..1d0a6e2 100644 --- a/opencase.module +++ b/opencase.module @@ -19,12 +19,17 @@ function opencase_block_access(\Drupal\block\Entity\Block $block, $operation, \D $route_name = \Drupal::routeMatch()->getRouteName(); $routes_where_it_should_be_shown = [ 'entity.oc_actor.canonical', + 'entity.oc_actor.edit_form', + 'entity.oc_actor.add_form', 'view.cases.page_1', 'entity.oc_case.canonical', + 'entity.oc_case.edit_form', + 'entity.oc_case.add_form', 'view.activities.page_1', - 'entity.oc_activity.canonical' + 'entity.oc_activity.canonical', + 'entity.oc_activity.edit_form', + 'entity.oc_activity.add_form' ]; - error_log(!in_array($route_name, $routes_where_it_should_be_shown)); return \Drupal\Core\Access\AccessResult::forbiddenIf(!in_array($route_name, $routes_where_it_should_be_shown)) ->addCacheableDependency($block); } diff --git a/src/Plugin/Block/ContextualMenu.php b/src/Plugin/Block/ContextualMenu.php index d7dad03..bbfa5b7 100644 --- a/src/Plugin/Block/ContextualMenu.php +++ b/src/Plugin/Block/ContextualMenu.php @@ -28,20 +28,29 @@ class ContextualMenu extends BlockBase { $route_name = \Drupal::routeMatch()->getRouteName(); switch ($route_name) { case 'entity.oc_actor.canonical': + case 'entity.oc_actor.edit_form': $markup = $this->actorPage(); break; case 'view.cases.page_1': $markup = $this->caseListPage(); break; case 'entity.oc_case.canonical': + case 'entity.oc_case.edit_form': $markup = $this->casePage(); break; + case 'entity.oc_case.add_form': + $markup = $this->caseAddPage(); + break; case 'view.activities.page_1': $markup = $this->activityListPage(); break; case 'entity.oc_activity.canonical': + case 'entity.oc_activity.edit_form': $markup = $this->activityPage(); break; + case 'entity.oc_activity.add_form': + $markup = $this->activityAddPage(); + break; } $build = []; @@ -87,6 +96,17 @@ class ContextualMenu extends BlockBase { return $this->asNavLinks([$link]); } + /** + * Contextual menu for Add-New-Case page + * - Link to Case list for the actor + */ + private function caseAddPage() { + $actor_id = \Drupal::request()->query->get('actor_id'); + $actor = \Drupal::entityTypeManager()->getStorage('oc_actor')->load($actor_id); + $link = $this->getCaseListLink($actor); + return $this->asNavLinks([$link]); + } + /** * Contextual menu for Activity list page * - Link to the case that the activity list is for @@ -113,6 +133,18 @@ class ContextualMenu extends BlockBase { } + /** + * Contextual menu for Add-New-Activity page + * - Links to the activity list for the case + */ + private function activityAddPage() { + $case_id = \Drupal::request()->query->get('case_id'); + $case = \Drupal::entityTypeManager()->getStorage('oc_case')->load($case_id); + $link = $this->getActivityListLink($case); + return $this->asNavLinks([$link]); + } + + /** * Given an case entity, returns a link to the activity list */