You are here

class MenuLinkAdd in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/menu_ui/src/Plugin/Menu/LocalAction/MenuLinkAdd.php \Drupal\menu_ui\Plugin\Menu\LocalAction\MenuLinkAdd
  2. 9 core/modules/menu_ui/src/Plugin/Menu/LocalAction/MenuLinkAdd.php \Drupal\menu_ui\Plugin\Menu\LocalAction\MenuLinkAdd

Modifies the 'Add link' local action to add a destination.

Hierarchy

Expanded class hierarchy of MenuLinkAdd

1 string reference to 'MenuLinkAdd'
menu_ui.links.action.yml in core/modules/menu_ui/menu_ui.links.action.yml
core/modules/menu_ui/menu_ui.links.action.yml

File

core/modules/menu_ui/src/Plugin/Menu/LocalAction/MenuLinkAdd.php, line 14

Namespace

Drupal\menu_ui\Plugin\Menu\LocalAction
View source
class MenuLinkAdd extends LocalActionDefault {

  /**
   * The redirect destination.
   *
   * @var \Drupal\Core\Routing\RedirectDestinationInterface
   */
  private $redirectDestination;

  /**
   * Constructs a MenuLinkAdd object.
   *
   * @param array $configuration
   *   A configuration array containing information about the plugin instance.
   * @param string $plugin_id
   *   The plugin_id for the plugin instance.
   * @param mixed $plugin_definition
   *   The plugin implementation definition.
   * @param \Drupal\Core\Routing\RouteProviderInterface $route_provider
   *   The route provider to load routes by name.
   * @param \Drupal\Core\Routing\RedirectDestinationInterface $redirect_destination
   *   The redirect destination.
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, RouteProviderInterface $route_provider, RedirectDestinationInterface $redirect_destination) {
    parent::__construct($configuration, $plugin_id, $plugin_definition, $route_provider);
    $this->redirectDestination = $redirect_destination;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    return new static($configuration, $plugin_id, $plugin_definition, $container
      ->get('router.route_provider'), $container
      ->get('redirect.destination'));
  }

  /**
   * {@inheritdoc}
   */
  public function getOptions(RouteMatchInterface $route_match) {
    $options = parent::getOptions($route_match);

    // Append the current path as destination to the query string.
    $options['query']['destination'] = $this->redirectDestination
      ->get();
    return $options;
  }

}

Members