Added actor type links to see-all menu

This commit is contained in:
naomi 2022-04-08 12:02:53 +01:00
parent 34b7a1c7c9
commit b85cbaf398
3 changed files with 70 additions and 1 deletions

View File

@ -2,7 +2,12 @@ opencase.see_all:
title: 'See all...'
menu_name: opencase
route_name: opencase.opencase_cases_menu
weight: 0
weight:
opencase.see_all_people_links:
class: Drupal\opencase\Plugin\Menu\SeeAllActorsMenuLink
deriver: Drupal\opencase\Plugin\Derivative\SeeAllActorsMenuLink
menu_name: opencase
parent: opencase.see_all
opencase.opencase_add_new_things_menu:
title: 'Add new...'
menu_name: opencase

View File

@ -0,0 +1,55 @@
<?php
namespace Drupal\opencase\Plugin\Derivative;
use Drupal\Component\Plugin\Derivative\DeriverBase;
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
 * Derivative class that provides the menu links adding various types of actors
 */
class SeeAllActorsMenuLink extends DeriverBase implements ContainerDeriverInterface {
/**
   * @var EntityTypeManagerInterface $entityTypeManager.
   */
protected $entityTypeManager;
/**
   * Creates a AddActorsMenuLink instance.
   *
   * @param $base_plugin_id
   * @param EntityTypeManagerInterface $entity_type_manager
   */
public function __construct($base_plugin_id, EntityTypeManagerInterface $entity_type_manager) {
$this->entityTypeManager = $entity_type_manager;
}
/**
   * {@inheritdoc}
   */
public static function create(ContainerInterface $container, $base_plugin_id) {
return new static(
$base_plugin_id,
$container->get('entity_type.manager')
);
}
/**
   * {@inheritdoc}
   */
public function getDerivativeDefinitions($base_plugin_definition) {
$links = [];
$actorTypes = $this->entityTypeManager->getStorage('oc_actor_type')->loadMultiple();
foreach ($actorTypes as $id => $actorType) {
$links[$id] = [
'title' => $actorType->label(),
'route_name' => "view.actors.page_1",
'route_parameters' => ['type' => $actorType->id()]
] + $base_plugin_definition;
}
return $links;
}
}

View File

@ -0,0 +1,9 @@
<?php
namespace Drupal\opencase\Plugin\Menu;
use Drupal\Core\Menu\MenuLinkDefault;
/**
* Represents a menu link for seeing all actors of various types.
*/
class SeeAllActorsMenuLink extends MenuLinkDefault {}