You are here

class QuickFormMenuLink in farmOS 2.x

Provides menu links for quick forms.

Hierarchy

Expanded class hierarchy of QuickFormMenuLink

1 string reference to 'QuickFormMenuLink'
farm_quick.links.menu.yml in modules/core/quick/farm_quick.links.menu.yml
modules/core/quick/farm_quick.links.menu.yml

File

modules/core/quick/src/Plugin/Derivative/QuickFormMenuLink.php, line 13

Namespace

Drupal\farm_quick\Plugin\Derivative
View source
class QuickFormMenuLink extends DeriverBase implements ContainerDeriverInterface {

  /**
   * The quick form manager.
   *
   * @var \Drupal\farm_quick\QuickFormManager
   */
  protected $quickFormManager;

  /**
   * FarmQuickMenuLink constructor.
   *
   * @param string $base_plugin_id
   *   The base plugin ID.
   * @param \Drupal\farm_quick\QuickFormManager $quick_form_manager
   *   The quick form manager.
   */
  public function __construct(string $base_plugin_id, QuickFormManager $quick_form_manager) {
    $this->quickFormManager = $quick_form_manager;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, $base_plugin_id) {
    return new static($base_plugin_id, $container
      ->get('plugin.manager.quick_form'));
  }

  /**
   * {@inheritdoc}
   */
  public function getDerivativeDefinitions($base_plugin_definition) {
    $links = [];

    // Load quick forms.
    $quick_forms = $this->quickFormManager
      ->getDefinitions();

    // Add a top level menu parent.
    if (!empty($quick_forms)) {
      $links['farm.quick'] = [
        'title' => 'Quick forms',
        'route_name' => 'farm.quick',
        'weight' => -100,
      ] + $base_plugin_definition;
    }

    // Add a link for each quick form.
    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;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DeriverBase::$derivatives protected property List of derivative definitions. 1
DeriverBase::getDerivativeDefinition public function Gets the definition of a derivative plugin. Overrides DeriverInterface::getDerivativeDefinition
QuickFormMenuLink::$quickFormManager protected property The quick form manager.
QuickFormMenuLink::create public static function Creates a new class instance. Overrides ContainerDeriverInterface::create
QuickFormMenuLink::getDerivativeDefinitions public function Gets the definition of all derivatives of a base plugin. Overrides DeriverBase::getDerivativeDefinitions
QuickFormMenuLink::__construct public function FarmQuickMenuLink constructor.