Removed contextual menu block, as it does not work (keeps disappearing).

This commit is contained in:
naomi 2021-04-14 11:36:00 +01:00
parent 0df9cfecc8
commit b7cfaa9f64
1 changed files with 0 additions and 65 deletions

View File

@ -1,65 +0,0 @@
<?php
namespace Drupal\opencase_no_cases\Plugin\Block;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Link;
use Drupal\Core\Url;
/**
* Provides a 'ContextualMenu' block.
*
* Displays links for adding activities against a person.
*
* @Block(
* id = "opencase_no_cases_contextual_menu",
* admin_label = @Translation("OpenCase Contextual Menu"),
* )
*/
class ContextualMenu extends BlockBase {
/**
* {@inheritdoc}
*/
public function build() {
$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' ) {
$markup = $this->actorPage();
$build = [];
$build['contextual_menu'] = [
'#markup' => "<div id='opencase_contextual_menu'>$markup</div",
'#cache' => ['max-age' => 0]
];
return $build;
}
}
/**
* Contextual menu for Actor page
* - Links to add activities of various types
*/
private function actorPage() {
$actor_id = \Drupal::routeMatch()->getParameter('oc_actor')->id();
return $this->generateLinksForAddingNewActivities("Add activity", $actor_id);
}
/**
* returns html markup.
*/
private function generateLinksForAddingNewActivities($title, $actor_id) {
$title = t($title);
$markup = "<br /><p><strong>$title: </strong>";
$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) {
$label = $activityType['label'];
$url = \Drupal\Core\Url::fromRoute("entity.oc_activity.add_form", ['oc_activity_type' => $machine_name]);
$url->setOption('query', ['actor_id' => $actor_id, 'destination' => $redirect_destination]);
$link = \Drupal\Core\Link::fromTextAndUrl($label, $url)->toString();
$markup .= "&nbsp;&nbsp; <span class='$machine_name add-activity-link'>$link</span>";
}
$markup .= "</p>";
return "<div class='openactor_add_links'>$markup</div>";
}
}