Changed how destination is set in contextual menu
This commit is contained in:
parent
0f0281c58c
commit
1d257538fe
@ -23,8 +23,8 @@ class ContextualMenu extends BlockBase {
|
|||||||
*/
|
*/
|
||||||
public function build() {
|
public function build() {
|
||||||
$route_name = \Drupal::routeMatch()->getRouteName();
|
$route_name = \Drupal::routeMatch()->getRouteName();
|
||||||
|
\Drupal::logger('my_module')->error(\Drupal::routeMatch()->getParameter('oc_actor')->bundle());
|
||||||
if ($route_name == 'entity.oc_actor.canonical' && \Drupal::routeMatch()->getParameter('oc_actor')->bundle() == 'client' ) {
|
if ($route_name == 'entity.oc_actor.canonical' && \Drupal::routeMatch()->getParameter('oc_actor')->bundle() == 'client' ) {
|
||||||
;
|
|
||||||
$markup = $this->actorPage();
|
$markup = $this->actorPage();
|
||||||
$build = [];
|
$build = [];
|
||||||
$build['contextual_menu'] = [
|
$build['contextual_menu'] = [
|
||||||
@ -42,20 +42,20 @@ class ContextualMenu extends BlockBase {
|
|||||||
*/
|
*/
|
||||||
private function actorPage() {
|
private function actorPage() {
|
||||||
$actor_id = \Drupal::routeMatch()->getParameter('oc_actor')->id();
|
$actor_id = \Drupal::routeMatch()->getParameter('oc_actor')->id();
|
||||||
$current_path = \Drupal::service('path.current')->getPath();
|
return $this->generateLinksForAddingNewActivities("Add activity", $actor_id);
|
||||||
return $this->generateLinksForAddingNewActivities("Add activity", ['actor_id' => $actor_id, 'destination' => $current_path]);
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* returns html markup.
|
* returns html markup.
|
||||||
*/
|
*/
|
||||||
private function generateLinksForAddingNewActivities($title, $query = []) {
|
private function generateLinksForAddingNewActivities($title, $actor_id) {
|
||||||
$title = t($title);
|
$title = t($title);
|
||||||
$markup = "<br /><p><strong>$title: </strong>";
|
$markup = "<br /><p><strong>$title: </strong>";
|
||||||
$allActivityTypes = \Drupal::service('entity_type.bundle.info')->getBundleInfo('oc_activity');
|
$allActivityTypes = \Drupal::service('entity_type.bundle.info')->getBundleInfo('oc_activity');
|
||||||
|
$redirect_destination = \Drupal\Core\Url::fromRoute("entity.oc_actor.canonical", ['oc_actor' => $actor_id])->toString();
|
||||||
foreach($allActivityTypes as $machine_name => $activityType) {
|
foreach($allActivityTypes as $machine_name => $activityType) {
|
||||||
$label = $activityType['label'];
|
$label = $activityType['label'];
|
||||||
$url = \Drupal\Core\Url::fromRoute("entity.oc_activity.add_form", ['oc_activity_type' => $machine_name]);
|
$url = \Drupal\Core\Url::fromRoute("entity.oc_activity.add_form", ['oc_activity_type' => $machine_name]);
|
||||||
$url->setOption('query', $query);
|
$url->setOption('query', ['actor_id' => $actor_id, 'destination' => $redirect_destination]);
|
||||||
$link = \Drupal\Core\Link::fromTextAndUrl($label, $url)->toString();
|
$link = \Drupal\Core\Link::fromTextAndUrl($label, $url)->toString();
|
||||||
$markup .= " $link";
|
$markup .= " $link";
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user