Merge branch 'master' of ssh://git.autonomic.zone:2222/autonomic-cooperative/opencase
This commit is contained in:
52
src/Plugin/Block/AddActivity.php
Normal file
52
src/Plugin/Block/AddActivity.php
Normal file
@ -0,0 +1,52 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace Drupal\opencase\Plugin\Block;
|
||||
|
||||
use Drupal\Core\Block\BlockBase;
|
||||
|
||||
/**
|
||||
* Provides a Block with some help text about actor type fields
|
||||
*
|
||||
* @Block(
|
||||
* id = "add_activity",
|
||||
* admin_label = @Translation("Add Activity"),
|
||||
* category = @Translation("Opencase"),
|
||||
* )
|
||||
*/
|
||||
class AddActivity extends BlockBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function build():array {
|
||||
$actor = \Drupal::routeMatch()->getParameter('oc_actor');
|
||||
$target_id = $actor->id();
|
||||
$actorType = $actor->bundle();
|
||||
$markup = "<ul>";
|
||||
$activity_types = $this->getActivityTypesToDisplay($actorType);
|
||||
foreach($activity_types as $id => $info) {
|
||||
$label = $info['label'];
|
||||
$markup .= "<li><a href='/opencase/oc_activity/add/$id?target_id=$target_id&destination=/opencase/oc_actor/$target_id'>$label</a></li>";
|
||||
}
|
||||
$markup .= "</ul>";
|
||||
return array('#markup' => $markup);
|
||||
}
|
||||
|
||||
public function getCacheMaxAge():int {
|
||||
return 0;
|
||||
}
|
||||
|
||||
private function getActivityTypesToDisplay(string $actorType): array {
|
||||
// Client modules will provide a list of what activity types (bundles) are relevant for each actor type.
|
||||
// Check if they are implemented, and if so display them.
|
||||
$implemented_activity_types = \Drupal::service('entity_type.bundle.info')->getBundleInfo('oc_activity');
|
||||
$relevant_activity_type_ids = \Drupal::moduleHandler()->invokeAll('relevant_activity_type_ids', [$actorType]);
|
||||
$activity_types_to_display = [];
|
||||
foreach ($relevant_activity_type_ids as $type_id) {
|
||||
if (array_key_exists($type_id, $implemented_activity_types)) {
|
||||
$activity_types_to_display[$type_id] = $implemented_activity_types[$type_id];
|
||||
}
|
||||
}
|
||||
return $activity_types_to_display;
|
||||
}
|
||||
}
|
@ -45,7 +45,7 @@ class AddEventsMenuLink extends DeriverBase implements ContainerDeriverInterface
|
||||
$eventTypes = $this->entityTypeManager->getStorage('oc_event_type')->loadMultiple();
|
||||
foreach ($eventTypes as $id => $eventType) {
|
||||
$links[$id] = [
|
||||
'title' => $eventType->label() . " Event",
|
||||
'title' => $eventType->label(),
|
||||
'route_name' => "entity.oc_event.add_form",
|
||||
'route_parameters' => ['oc_event_type' => $eventType->id()]
|
||||
] + $base_plugin_definition;
|
||||
|
@ -45,7 +45,7 @@ class SeeAllActorsMenuLink extends DeriverBase implements ContainerDeriverInterf
|
||||
$actorTypes = $this->entityTypeManager->getStorage('oc_actor_type')->loadMultiple();
|
||||
foreach ($actorTypes as $id => $actorType) {
|
||||
$links[$id] = [
|
||||
'title' => $actorType->label(),
|
||||
'title' => \Drupal\opencase\Pluraliser::pluralise($actorType->label()),
|
||||
'route_name' => "view.actors.page_1",
|
||||
'route_parameters' => ['type' => $actorType->id()]
|
||||
] + $base_plugin_definition;
|
||||
|
@ -50,7 +50,7 @@ class SeeAllEventsMenuLink extends DeriverBase implements ContainerDeriverInterf
|
||||
$eventTypes = $this->entityTypeManager->getStorage('oc_event_type')->loadMultiple();
|
||||
foreach ($eventTypes as $id => $eventType) {
|
||||
$links[$id] = [
|
||||
'title' => $eventType->label(),
|
||||
'title' => \Drupal\opencase\Pluraliser::pluralise($eventType->label()),
|
||||
'route_name' => "view.events.page_1",
|
||||
'route_parameters' => ['type' => $eventType->id()]
|
||||
] + $base_plugin_definition;
|
||||
|
@ -45,7 +45,7 @@ class SeeAllOrganisationsMenuLink extends DeriverBase implements ContainerDerive
|
||||
$organisationTypes = $this->entityTypeManager->getStorage('oc_organisation_type')->loadMultiple();
|
||||
foreach ($organisationTypes as $id => $organisationType) {
|
||||
$links[$id] = [
|
||||
'title' => $organisationType->label(),
|
||||
'title' => \Drupal\opencase\Pluraliser::pluralise($organisationType->label()),
|
||||
'route_name' => "view.organisations.page_1",
|
||||
'route_parameters' => ['type' => $organisationType->id()]
|
||||
] + $base_plugin_definition;
|
||||
|
9
src/Pluraliser.php
Normal file
9
src/Pluraliser.php
Normal file
@ -0,0 +1,9 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Drupal\opencase;
|
||||
|
||||
class Pluraliser {
|
||||
public static function pluralise($text) {
|
||||
return $text . "s";
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user