<?php

namespace Drupal\nodehive_core_space_dashboard\Plugin\Menu\LocalAction;

use Drupal\Core\Menu\LocalActionDefault;
use Drupal\Core\Routing\RouteMatchInterface;

/**
 * Defines a local action that passes the space ID as a query parameter.
 */
class AddMenuLocalAction extends LocalActionDefault {

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

    $space = $route_match->getParameter('nodehive_space');
    if ($space) {
      $space_id = is_object($space) ? $space->id() : $space;
      $options['query']['space'] = $space_id;
      $options['query']['destination'] = '/space/' . $space_id . '/menus';
    }

    return $options;
  }

}
