Create human-readable metadata profiles of field config.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

75 lines
2.1 KiB

<?php
namespace Drupal\metadata_profile\Plugin\Derivative;
use Drupal\Component\Plugin\Derivative\DeriverBase;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Symfony\Component\DependencyInjection\ContainerInterface;
class MetadataProfileDisplayTask extends DeriverBase implements ContainerDeriverInterface
{
use StringTranslationTrait;
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* Creates an FieldUiLocalTask object.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager service.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager) {
$this->entityTypeManager = $entity_type_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, $base_plugin_id) {
return new static(
$container->get('entity_type.manager')
);
}
/**
* {@inheritdoc}
*/
public function getDerivativeDefinitions($base_plugin_definition) {
$this->derivatives = [];
foreach ($this->entityTypeManager->getDefinitions() as $entity_type_id => $entity_type) {
// Special handling of Taxonomy. See https://www.drupal.org/node/2822546
if ($entity_type_id == "taxonomy_vocabulary") {
$base_route = "entity.{$entity_type_id}.overview_form";
}
else {
$base_route = "entity.{$entity_type_id}.edit_form";
}
if ($entity_type->hasLinkTemplate('metadata-profile')) {
$this->derivatives["$entity_type_id.metadata_profile_tab"] = [
'route_name' => "entity.{$entity_type_id}.metadata_profile",
'title' => $this->t('Metadata Profile'),
'base_route' => $base_route,
'weight' => 100,
];
}
}
foreach ($this->derivatives as &$entry) {
$entry += $base_plugin_definition;
}
return $this->derivatives;
}
}