Added link to case list, when viewing case
It relies on the referer, and isn't very good.
This commit is contained in:
parent
7cf4ee557b
commit
b89cfcc2ee
@ -277,6 +277,9 @@ class OCCase extends RevisionableContentEntityBase implements OCCaseInterface {
|
|||||||
'placeholder' => '',
|
'placeholder' => '',
|
||||||
],
|
],
|
||||||
])
|
])
|
||||||
|
->setDisplayOptions('view', [
|
||||||
|
'label' => 'above',
|
||||||
|
])
|
||||||
->setDefaultValueCallback('Drupal\opencase_entities\Entity\OCCase::defaultVal')
|
->setDefaultValueCallback('Drupal\opencase_entities\Entity\OCCase::defaultVal')
|
||||||
->setRequired(TRUE);
|
->setRequired(TRUE);
|
||||||
|
|
||||||
|
@ -36,6 +36,9 @@ class ContextualMenu extends BlockBase {
|
|||||||
case 'view.activities.page_1':
|
case 'view.activities.page_1':
|
||||||
$markup = $this->activityListPage();
|
$markup = $this->activityListPage();
|
||||||
break;
|
break;
|
||||||
|
case 'entity.oc_activity.canonical':
|
||||||
|
$markup = $this->activityPage();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
$build = [];
|
$build = [];
|
||||||
@ -53,47 +56,83 @@ class ContextualMenu extends BlockBase {
|
|||||||
*/
|
*/
|
||||||
private function actorPage() {
|
private function actorPage() {
|
||||||
$actor = \Drupal::routeMatch()->getParameter('oc_actor');
|
$actor = \Drupal::routeMatch()->getParameter('oc_actor');
|
||||||
$url = Url::fromRoute('view.cases.page_1', array('actor_id' => $actor->id()));
|
$link = $this->getCaseListLink($actor);
|
||||||
$link = Link::fromTextAndUrl(t("Case List"), $url)->toString();
|
|
||||||
return "<div class='opencase_nav_links'><p>$link</p></div>";
|
return "<div class='opencase_nav_links'><p>$link</p></div>";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contextual menu for Case list page
|
* Contextual menu for Case list page
|
||||||
* - Link to the actor that the case list is for
|
|
||||||
* - Links to add cases of various types
|
* - Links to add cases of various types
|
||||||
*/
|
*/
|
||||||
private function caseListPage() {
|
private function caseListPage() {
|
||||||
$actor_id = \Drupal::routeMatch()->getParameter('actor_id');
|
$actor_id = \Drupal::routeMatch()->getParameter('actor_id');
|
||||||
$actor = \Drupal::entityTypeManager()->getStorage('oc_actor')->load($actor_id);
|
$current_path = \Drupal::service('path.current')->getPath();
|
||||||
$link = $actor->toLink()->toString();
|
$markup .= Utils::generateAddLinks('oc_case', ['actor_id' => $actor_id, 'destination' => $current_path]);
|
||||||
$markup = "<div class='opencase_nav_links'><p>$link</p></div>";
|
|
||||||
$markup .= Utils::generateAddLinks('oc_case', ['actor_id' => $actor_id]);
|
|
||||||
return $markup;
|
return $markup;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contextual menu for Case page
|
* Contextual menu for Case page
|
||||||
* - Link to Activity list
|
* - Link to case list if user has just come from there
|
||||||
|
* - Link to Activity list for that case
|
||||||
*/
|
*/
|
||||||
private function casePage() {
|
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]);
|
||||||
|
$link = $this->getCaseListLink($actor);
|
||||||
|
$links .= "<p>$link</p>";
|
||||||
|
}
|
||||||
|
|
||||||
$case = \Drupal::routeMatch()->getParameter('oc_case');
|
$case = \Drupal::routeMatch()->getParameter('oc_case');
|
||||||
$url = Url::fromRoute('view.activities.page_1', array('case_id' => $case->id()));
|
$link = $this->getActivityListLink($case);
|
||||||
$link = Link::fromTextAndUrl(t("Activity List"), $url)->toString();
|
$links .= "<p>$link</p>";
|
||||||
return "<div class='opencase_nav_links'><p>$link</p></div>";
|
return "<div class='opencase_nav_links'>$links</div>";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contextual menu for Activity list page
|
* Contextual menu for Activity list page
|
||||||
* - Link to case
|
|
||||||
* - Links to add activities of various types
|
* - Links to add activities of various types
|
||||||
*/
|
*/
|
||||||
private function activityListPage() {
|
private function activityListPage() {
|
||||||
$case_id = \Drupal::routeMatch()->getParameter('case_id');
|
$case_id = \Drupal::routeMatch()->getParameter('case_id');
|
||||||
$case = \Drupal::entityTypeManager()->getStorage('oc_case')->load($case_id);
|
$current_path = \Drupal::service('path.current')->getPath();
|
||||||
$link = $case->toLink()->toString();
|
$markup .= Utils::generateAddLinks('oc_activity', ['case_id' => $case_id, 'destination' => $current_path]);
|
||||||
$markup = "<div class='opencase_nav_links'><p>$link</p></div>";
|
|
||||||
$markup .= Utils::generateAddLinks('oc_activity', ['case_id' => $case_id]);
|
|
||||||
return $markup;
|
return $markup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Contextual menu for Activity page
|
||||||
|
* - Links to the activity list for the case
|
||||||
|
*/
|
||||||
|
private function activityPage() {
|
||||||
|
$activity = \Drupal::routeMatch()->getParameter('oc_activity');
|
||||||
|
$case = $activity->oc_case->entity;
|
||||||
|
$link = $this->getActivityListLink($case);
|
||||||
|
return "<div class='opencase_nav_links'><p>$link</p></div>";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Given an case entity, returns a link to the activity list
|
||||||
|
*/
|
||||||
|
private function getActivityListLink($case) {
|
||||||
|
$url = Url::fromRoute('view.activities.page_1', array('case_id' => $case->id()));
|
||||||
|
return Link::fromTextAndUrl(t("Activity List for " . $case->getName()), $url)->toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Given an case entity, returns a link to the activity list
|
||||||
|
*/
|
||||||
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user