In contextual menu, passing through actor_id
so that we can always come back to the original actor
This commit is contained in:
parent
80f42c7bf3
commit
c151f84692
@ -92,8 +92,10 @@ class ContextualMenu extends BlockBase {
|
|||||||
*/
|
*/
|
||||||
private function casePage() {
|
private function casePage() {
|
||||||
$case = \Drupal::routeMatch()->getParameter('oc_case');
|
$case = \Drupal::routeMatch()->getParameter('oc_case');
|
||||||
$link = $this->getActivityListLink($case);
|
$actor_id = \Drupal::request()->query->get('actor_id');
|
||||||
return $this->asNavLinks([$link]);
|
$actor = \Drupal::entityTypeManager()->getStorage('oc_actor')->load($actor_id);
|
||||||
|
$links = [$this->getCaseListLink($actor), $this->getActivityListLink($case)];
|
||||||
|
return $this->asNavLinks($links);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -115,15 +117,18 @@ class ContextualMenu extends BlockBase {
|
|||||||
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);
|
$case = \Drupal::entityTypeManager()->getStorage('oc_case')->load($case_id);
|
||||||
$link = Link::fromTextAndUrl(t($case->getName() .": Case Details and Files"), $case->toUrl())->toString();
|
$url = $case->toUrl('canonical', $this->getOptions());
|
||||||
|
$link = Link::fromTextAndUrl(t($case->getName() .": Case Details and Files"), $url)->toString();
|
||||||
$markup = $this->asNavLinks([$link]);
|
$markup = $this->asNavLinks([$link]);
|
||||||
$current_path = \Drupal::service('path.current')->getPath();
|
$current_path = \Drupal::service('path.current')->getPath();
|
||||||
return $markup . Utils::generateAddLinks('oc_activity', "Add activity", ['case_id' => $case_id, 'destination' => $current_path]);
|
$actor_id = \Drupal::request()->query->get('actor_id');
|
||||||
|
$query = ['case_id' => $case_id, 'actor_id' => $actor_id, 'destination' => $current_path . "?actor_id=$actor_id"];
|
||||||
|
return $markup . Utils::generateAddLinks('oc_activity', "Add activity", $query);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contextual menu for Activity page
|
* Contextual menu for Activity page
|
||||||
* - Links to the activity list for the case
|
* - Link to the activity list for the case
|
||||||
*/
|
*/
|
||||||
private function activityPage() {
|
private function activityPage() {
|
||||||
$activity = \Drupal::routeMatch()->getParameter('oc_activity');
|
$activity = \Drupal::routeMatch()->getParameter('oc_activity');
|
||||||
@ -135,7 +140,7 @@ class ContextualMenu extends BlockBase {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Contextual menu for Add-New-Activity page
|
* Contextual menu for Add-New-Activity page
|
||||||
* - Links to the activity list for the case
|
* - Link to the activity list for the case
|
||||||
*/
|
*/
|
||||||
private function activityAddPage() {
|
private function activityAddPage() {
|
||||||
$case_id = \Drupal::request()->query->get('case_id');
|
$case_id = \Drupal::request()->query->get('case_id');
|
||||||
@ -149,7 +154,7 @@ class ContextualMenu extends BlockBase {
|
|||||||
* Given an case entity, returns a link to the activity list
|
* Given an case entity, returns a link to the activity list
|
||||||
*/
|
*/
|
||||||
private function getActivityListLink($case) {
|
private function getActivityListLink($case) {
|
||||||
$url = Url::fromRoute('view.activities.page_1', array('case_id' => $case->id()));
|
$url = Url::fromRoute('view.activities.page_1', array('case_id' => $case->id()), $this->getOptions());
|
||||||
return Link::fromTextAndUrl(t($case->getName() .": Activities"), $url)->toString();
|
return Link::fromTextAndUrl(t($case->getName() .": Activities"), $url)->toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,7 +162,7 @@ class ContextualMenu extends BlockBase {
|
|||||||
* Given an actor entity, returns a link to their case list
|
* Given an actor entity, returns a link to their case list
|
||||||
*/
|
*/
|
||||||
private function getCaseListLink($actor) {
|
private function getCaseListLink($actor) {
|
||||||
$url = Url::fromRoute('view.cases.page_1', array('actor_id' => $actor->id()));
|
$url = Url::fromRoute('view.cases.page_1', ['actor_id' => $actor->id()]);
|
||||||
return Link::fromTextAndUrl(t($actor->getName(). ": Cases"), $url)->toString();
|
return Link::fromTextAndUrl(t($actor->getName(). ": Cases"), $url)->toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -172,4 +177,17 @@ class ContextualMenu extends BlockBase {
|
|||||||
$title = t("Go to:");
|
$title = t("Go to:");
|
||||||
return "<div class='opencase_nav_links'><h1>$title</h1>$markup</div>";
|
return "<div class='opencase_nav_links'><h1>$title</h1>$markup</div>";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the actor_id from the query parameter, if any, to pass through to next page.
|
||||||
|
*/
|
||||||
|
private function getOptions() {
|
||||||
|
$options = [];
|
||||||
|
$actor_id = \Drupal::request()->query->get('actor_id');
|
||||||
|
if ($actor_id) {
|
||||||
|
$options = ['query' => ['actor_id' => $actor_id]];
|
||||||
|
}
|
||||||
|
return $options;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user