Loading node_weight.links.menu.yml +0 −3 Original line number Diff line number Diff line Loading @@ -5,8 +5,5 @@ node_weight.content: parent: 'system.admin_structure' node_weight.menu_links: title: 'Node weight menu' parent: 'node_weight.content' menu_name: node_weight_menu class: Drupal\node_weight\Plugin\Menu\NodeWeightMenuLink deriver: Drupal\node_weight\Plugin\Derivative\NodeWeightMenuLink src/Plugin/Derivative/NodeWeightMenuLink.php +32 −4 Original line number Diff line number Diff line Loading @@ -3,8 +3,10 @@ namespace Drupal\node_weight\Plugin\Derivative; use Drupal\Component\Plugin\Derivative\DeriverBase; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\StringTranslation\StringTranslationTrait; use Symfony\Component\DependencyInjection\ContainerInterface; /** Loading @@ -12,6 +14,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface; */ class NodeWeightMenuLink extends DeriverBase implements ContainerDeriverInterface { use StringTranslationTrait; /** * {@inheritdoc} * Loading @@ -19,16 +23,26 @@ class NodeWeightMenuLink extends DeriverBase implements ContainerDeriverInterfac */ protected $entityTypeManager; /** * The module handler. * * @var \Drupal\Core\Extension\ModuleHandlerInterface */ protected $moduleHandler; /** * Creates a NodeMenuLink instance. * * @param int $base_plugin_id * Base plugin id. * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager * Entity type manager. * The Entity type manager. * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler * The module handler. */ public function __construct($base_plugin_id, EntityTypeManagerInterface $entity_type_manager) { public function __construct($base_plugin_id, EntityTypeManagerInterface $entity_type_manager, ModuleHandlerInterface $module_handler) { $this->entityTypeManager = $entity_type_manager; $this->moduleHandler = $module_handler; } /** Loading @@ -37,7 +51,8 @@ class NodeWeightMenuLink extends DeriverBase implements ContainerDeriverInterfac public static function create(ContainerInterface $container, $base_plugin_id) { return new static( $base_plugin_id, $container->get('entity_type.manager') $container->get('entity_type.manager'), $container->get('module_handler') ); } Loading @@ -56,10 +71,23 @@ class NodeWeightMenuLink extends DeriverBase implements ContainerDeriverInterfac 'title' => $node_type->label(), 'route_name' => 'node_weight.order', 'route_parameters' => ['node_type' => $nto], ] + $base_plugin_definition; 'parent' => 'node_weight.content', ]; if ($this->moduleHandler->moduleExists('admin_toolbar_tools')) { $links['entity.node_type.node_weight.' . $node_type->id()] = [ 'title' => $this->t('Manage order'), 'route_name' => 'node_weight.order', 'route_parameters' => ['node_type' => $nto], 'parent' => 'admin_toolbar_tools.extra_links:entity.node_type.edit_form.' . $node_type->id(), ]; } } } foreach ($links as &$link) { $link += $base_plugin_definition; } return $links; } Loading Loading
node_weight.links.menu.yml +0 −3 Original line number Diff line number Diff line Loading @@ -5,8 +5,5 @@ node_weight.content: parent: 'system.admin_structure' node_weight.menu_links: title: 'Node weight menu' parent: 'node_weight.content' menu_name: node_weight_menu class: Drupal\node_weight\Plugin\Menu\NodeWeightMenuLink deriver: Drupal\node_weight\Plugin\Derivative\NodeWeightMenuLink
src/Plugin/Derivative/NodeWeightMenuLink.php +32 −4 Original line number Diff line number Diff line Loading @@ -3,8 +3,10 @@ namespace Drupal\node_weight\Plugin\Derivative; use Drupal\Component\Plugin\Derivative\DeriverBase; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\StringTranslation\StringTranslationTrait; use Symfony\Component\DependencyInjection\ContainerInterface; /** Loading @@ -12,6 +14,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface; */ class NodeWeightMenuLink extends DeriverBase implements ContainerDeriverInterface { use StringTranslationTrait; /** * {@inheritdoc} * Loading @@ -19,16 +23,26 @@ class NodeWeightMenuLink extends DeriverBase implements ContainerDeriverInterfac */ protected $entityTypeManager; /** * The module handler. * * @var \Drupal\Core\Extension\ModuleHandlerInterface */ protected $moduleHandler; /** * Creates a NodeMenuLink instance. * * @param int $base_plugin_id * Base plugin id. * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager * Entity type manager. * The Entity type manager. * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler * The module handler. */ public function __construct($base_plugin_id, EntityTypeManagerInterface $entity_type_manager) { public function __construct($base_plugin_id, EntityTypeManagerInterface $entity_type_manager, ModuleHandlerInterface $module_handler) { $this->entityTypeManager = $entity_type_manager; $this->moduleHandler = $module_handler; } /** Loading @@ -37,7 +51,8 @@ class NodeWeightMenuLink extends DeriverBase implements ContainerDeriverInterfac public static function create(ContainerInterface $container, $base_plugin_id) { return new static( $base_plugin_id, $container->get('entity_type.manager') $container->get('entity_type.manager'), $container->get('module_handler') ); } Loading @@ -56,10 +71,23 @@ class NodeWeightMenuLink extends DeriverBase implements ContainerDeriverInterfac 'title' => $node_type->label(), 'route_name' => 'node_weight.order', 'route_parameters' => ['node_type' => $nto], ] + $base_plugin_definition; 'parent' => 'node_weight.content', ]; if ($this->moduleHandler->moduleExists('admin_toolbar_tools')) { $links['entity.node_type.node_weight.' . $node_type->id()] = [ 'title' => $this->t('Manage order'), 'route_name' => 'node_weight.order', 'route_parameters' => ['node_type' => $nto], 'parent' => 'admin_toolbar_tools.extra_links:entity.node_type.edit_form.' . $node_type->id(), ]; } } } foreach ($links as &$link) { $link += $base_plugin_definition; } return $links; } Loading