From c1c981fdddd52aeb42b2a9ef701f0a4f12914c33 Mon Sep 17 00:00:00 2001 From: naomi Date: Thu, 3 May 2018 14:34:55 +0200 Subject: [PATCH] Modified page titles to give more info Also removed conditional link back to case list from a case - it only appears sometimes, so it is more confusing to have it than not. --- opencase.module | 26 ++++++++++++++++++++++++++ src/Plugin/Block/ContextualMenu.php | 23 ++++------------------- src/Plugin/Block/GlobalMenu.php | 1 - 3 files changed, 30 insertions(+), 20 deletions(-) diff --git a/opencase.module b/opencase.module index c3136db..b779e84 100644 --- a/opencase.module +++ b/opencase.module @@ -7,6 +7,32 @@ use Drupal\Core\Routing\RouteMatchInterface; +/** + * Implements hook_preprocess_page_title + * + * Modify the page title to include more information + */ +function opencase_preprocess_page_title(&$variables) { + + $route_name = \Drupal::routeMatch()->getRouteName(); + switch ($route_name) { + case 'entity.oc_case.canonical': + $case = \Drupal::routeMatch()->getParameter('oc_case'); + $variables['title'] = $case->getName() . ": Case Details and Files"; + break; + case 'view.cases.page_1': + $actor_id = \Drupal::routeMatch()->getParameter('actor_id'); + $actor = \Drupal::entityTypeManager()->getStorage('oc_actor')->load($actor_id); + $variables['title'] = $actor->getName() . ": Cases"; + break; + case 'view.activities.page_1': + $case_id = \Drupal::routeMatch()->getParameter('case_id'); + $case = \Drupal::entityTypeManager()->getStorage('oc_case')->load($case_id); + $variables['title'] = $case->getName() . ": Activities"; + break; + } +} + /** * Implements hook_help(). */ diff --git a/src/Plugin/Block/ContextualMenu.php b/src/Plugin/Block/ContextualMenu.php index 894fb12..0047d88 100644 --- a/src/Plugin/Block/ContextualMenu.php +++ b/src/Plugin/Block/ContextualMenu.php @@ -76,27 +76,12 @@ class ContextualMenu extends BlockBase { /** * Contextual menu for Case page - * - Link to case list if user has just come from there * - Link to Activity list for that case */ private function casePage() { - - $links = []; - - // Ascertain if user has come from a case list and if so link back - // This is fragle code, it needs doing better. - $referer = \Drupal::request()->headers->get('referer'); - $parts = parse_url($referer); - $path_parts= explode('/', $parts[path]); - if ($path_parts[4] == 'case_list') { - $actor = \Drupal::entityTypeManager()->getStorage('oc_actor')->load($path_parts[3]); - $links[] = $this->getCaseListLink($actor); - } - - // Now get the link to the activity list for the case. $case = \Drupal::routeMatch()->getParameter('oc_case'); - $links[] = $this->getActivityListLink($case); - return $this->asNavLinks($links); + $link = $this->getActivityListLink($case); + return $this->asNavLinks([$link]); } /** @@ -107,7 +92,7 @@ class ContextualMenu extends BlockBase { private function activityListPage() { $case_id = \Drupal::routeMatch()->getParameter('case_id'); $case = \Drupal::entityTypeManager()->getStorage('oc_case')->load($case_id); - $link = Link::fromTextAndUrl(t($case->getName() .": Details and Files"), $case->toUrl())->toString(); + $link = Link::fromTextAndUrl(t($case->getName() .": Case Details and Files"), $case->toUrl())->toString(); $markup = $this->asNavLinks([$link]); $current_path = \Drupal::service('path.current')->getPath(); return $markup . Utils::generateAddLinks('oc_activity', "Add activity", ['case_id' => $case_id, 'destination' => $current_path]); @@ -138,7 +123,7 @@ class ContextualMenu extends BlockBase { */ private function getCaseListLink($actor) { $url = Url::fromRoute('view.cases.page_1', array('actor_id' => $actor->id())); - return Link::fromTextAndUrl(t("Case List for " . $actor->getName()), $url)->toString(); + return Link::fromTextAndUrl(t($actor->getName(). ": Cases"), $url)->toString(); } /** diff --git a/src/Plugin/Block/GlobalMenu.php b/src/Plugin/Block/GlobalMenu.php index 15e21f4..fe64dd9 100644 --- a/src/Plugin/Block/GlobalMenu.php +++ b/src/Plugin/Block/GlobalMenu.php @@ -26,7 +26,6 @@ class GlobalMenu extends BlockBase { $markup .= Utils::generateAddLinks('oc_actor', 'Add new'); $build['global_menu'] = [ '#markup' => "
$markup ['max-age' => 0] ]; return $build; }