ComponentSectionFormsLocalTasks.php in Module Builder 8.3
File
src/Plugin/Derivative/ComponentSectionFormsLocalTasks.php
View source
<?php
namespace Drupal\module_builder\Plugin\Derivative;
use Drupal\Component\Plugin\Derivative\DeriverBase;
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class ComponentSectionFormsLocalTasks extends DeriverBase implements ContainerDeriverInterface {
protected $entityTypeManager;
public function __construct(EntityTypeManagerInterface $entity_type_manager) {
$this->entityTypeManager = $entity_type_manager;
}
public static function create(ContainerInterface $container, $base_plugin_id) {
return new static($container
->get('entity_type.manager'));
}
public function getDerivativeDefinitions($base_plugin_definition) {
$entity_types = $this->entityTypeManager
->getDefinitions();
foreach ($entity_types as $entity_type_id => $entity_type) {
if (!$entity_type
->hasHandlerClass('component_sections')) {
continue;
}
$component_sections_handler = $this->entityTypeManager
->getHandler($entity_type_id, 'component_sections');
$section_route_data = $component_sections_handler
->getFormTabLocalTasksData();
$weight = 0;
foreach ($section_route_data as $form_op => $title) {
$task = $base_plugin_definition;
$weight++;
$task['title'] = $title;
$task['weight'] = $weight;
$task['route_name'] = "entity.{$entity_type_id}.{$form_op}_form";
$task['base_route'] = "entity.{$entity_type_id}.edit_form";
$this->derivatives["entity.{$entity_type_id}.{$form_op}_form"] = $task;
}
}
return $this->derivatives;
}
}