3
0
Fork 0
mirror of https://github.com/farmOS/farmOS.git synced 2024-02-23 11:37:38 +01:00

Consolidate asset and log tab generation to deriver class.

This commit is contained in:
Paul Weidner 2022-09-21 14:56:28 -07:00 committed by Michael Stenta
parent 7c55dfe8c1
commit 63a63935a3
2 changed files with 36 additions and 24 deletions

View file

@ -15,20 +15,6 @@ farm.asset.logs.all:
farm.asset.logs.type:
deriver: Drupal\farm_ui_views\Plugin\Derivative\FarmLogViewsTaskLink
# Add asset/log view tabs to taxonomy terms.
farm.taxonomy_term.assets:
title: 'Assets'
route_name: view.farm_asset.page_term
route_parameters:
entity_bundle: 'all'
base_route: entity.taxonomy_term.canonical
weight: 50
farm.taxonomy_term.logs:
title: 'Logs'
route_name: view.farm_log.page_term
route_parameters:
entity_bundle: 'all'
base_route: entity.taxonomy_term.canonical
weight: 50
# Add asset and log view tabs to taxonomy terms.
farm.taxonomy_term.entities.type:
deriver: Drupal\farm_ui_views\Plugin\Derivative\FarmTaxonomyTermViewsTaskLink

View file

@ -4,6 +4,7 @@ namespace Drupal\farm_ui_views\Plugin\Derivative;
use Drupal\Component\Plugin\Derivative\DeriverBase;
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Symfony\Component\DependencyInjection\ContainerInterface;
@ -15,6 +16,13 @@ class FarmTaxonomyTermViewsTaskLink extends DeriverBase implements ContainerDeri
use StringTranslationTrait;
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* The entity type bundle info.
*
@ -25,10 +33,13 @@ class FarmTaxonomyTermViewsTaskLink extends DeriverBase implements ContainerDeri
/**
* Constructs a FarmTaxonomyTermViewsTaskLink instance.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager service.
* @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $entity_bundle_info
* The entity type bundle info service.
*/
public function __construct(EntityTypeBundleInfoInterface $entity_bundle_info) {
public function __construct(EntityTypeManagerInterface $entity_type_manager, EntityTypeBundleInfoInterface $entity_bundle_info) {
$this->entityTypeManager = $entity_type_manager;
$this->entityTypeBundleInfo = $entity_bundle_info;
}
@ -37,6 +48,7 @@ class FarmTaxonomyTermViewsTaskLink extends DeriverBase implements ContainerDeri
*/
public static function create(ContainerInterface $container, $base_plugin_id) {
return new static(
$container->get('entity_type.manager'),
$container->get('entity_type.bundle.info')
);
}
@ -48,25 +60,39 @@ class FarmTaxonomyTermViewsTaskLink extends DeriverBase implements ContainerDeri
$links = [];
// Add asset and log task links to taxonomy term pages.
foreach (['asset', 'log'] as $entity_type) {
foreach (['asset', 'log'] as $entity_type_id) {
// Get the entity type definition.
$entity_type = $this->entityTypeManager->getDefinition($entity_type_id);
// Add tab for each entity type.
$links["farm.taxonomy_term.{$entity_type_id}s"] = [
'title' => $entity_type->getCollectionLabel(),
'route_name' => "view.farm_$entity_type_id.page_term",
'route_parameters' => [
'entity_bundle' => 'all',
],
'base_route' => 'entity.taxonomy_term.canonical',
'weight' => 50,
] + $base_plugin_definition;
// Add default "All" secondary tab for each entity type.
$links["farm.taxonomy_term.{$entity_type}s.all"] = [
$links["farm.taxonomy_term.{$entity_type_id}s.all"] = [
'title' => $this->t('All'),
'parent_id' => "farm.taxonomy_term.{$entity_type}s",
'route_name' => "view.farm_$entity_type.page_term",
'parent_id' => "farm.taxonomy_term.entities.type:farm.taxonomy_term.{$entity_type_id}s",
'route_name' => "view.farm_$entity_type_id.page_term",
'route_parameters' => [
'entity_bundle' => 'all',
],
] + $base_plugin_definition;
// Add secondary tab for each entity bundle.
$entity_bundles = $this->entityTypeBundleInfo->getBundleInfo($entity_type);
$entity_bundles = $this->entityTypeBundleInfo->getBundleInfo($entity_type_id);
foreach ($entity_bundles as $entity_bundle => $info) {
$links["farm.taxonomy_term.{$entity_type}s.$entity_bundle"] = [
$links["farm.taxonomy_term.{$entity_type_id}s.$entity_bundle"] = [
'title' => $info['label'],
'parent_id' => "farm.taxonomy_term.{$entity_type}s",
'route_name' => "view.farm_$entity_type.page_term",
'parent_id' => "farm.taxonomy_term.entities.type:farm.taxonomy_term.{$entity_type_id}s",
'route_name' => "view.farm_$entity_type_id.page_term",
'route_parameters' => [
'entity_bundle' => $entity_bundle,
],