QuickFormMenuLink.php in farmOS 2.x
File
modules/core/quick/src/Plugin/Derivative/QuickFormMenuLink.php
View source
<?php
namespace Drupal\farm_quick\Plugin\Derivative;
use Drupal\Component\Plugin\Derivative\DeriverBase;
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
use Drupal\farm_quick\QuickFormManager;
use Symfony\Component\DependencyInjection\ContainerInterface;
class QuickFormMenuLink extends DeriverBase implements ContainerDeriverInterface {
protected $quickFormManager;
public function __construct(string $base_plugin_id, QuickFormManager $quick_form_manager) {
$this->quickFormManager = $quick_form_manager;
}
public static function create(ContainerInterface $container, $base_plugin_id) {
return new static($base_plugin_id, $container
->get('plugin.manager.quick_form'));
}
public function getDerivativeDefinitions($base_plugin_definition) {
$links = [];
$quick_forms = $this->quickFormManager
->getDefinitions();
if (!empty($quick_forms)) {
$links['farm.quick'] = [
'title' => 'Quick forms',
'route_name' => 'farm.quick',
'weight' => -100,
] + $base_plugin_definition;
}
foreach ($quick_forms as $quick_form) {
$route_id = 'farm.quick.' . $quick_form['id'];
$links[$route_id] = [
'title' => $quick_form['label'],
'parent' => 'farm.quick',
'route_name' => $route_id,
] + $base_plugin_definition;
}
return $links;
}
}