Merge branch 'dev'

This commit is contained in:
naomi 2021-03-23 18:25:40 +00:00
commit 998f72f505

View File

@ -23,6 +23,7 @@ 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 = [];
@ -41,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 .= "&nbsp;&nbsp; $link"; $markup .= "&nbsp;&nbsp; $link";
} }