function ViewsFormHelperTrait::buildFormUrl

Creates the menu path for a standard AJAX form given the form state.

Return value

\Drupal\Core\Url The URL object pointing to the form URL.

File

core/modules/views/src/ViewsFormHelperTrait.php, line 108

Class

ViewsFormHelperTrait
Provides reusable code to be shared by Views forms.

Namespace

Drupal\views

Code

protected function buildFormUrl(FormStateInterface $formState) : Url {
  $ajax = !$formState->get('ajax') ? 'nojs' : 'ajax';
  $name = $formState->get('view')
    ->id();
  $formKey = $formState->get('form_key');
  $displayId = $formState->get('display_id');
  $formKey = str_replace('-', '_', $formKey);
  $routeName = "views_ui.form_{$formKey}";
  $routeParameters = [
    'js' => $ajax,
    'view' => $name,
    'display_id' => $displayId,
  ];
  $url = Url::fromRoute($routeName, $routeParameters);
  if ($type = $formState->get('type')) {
    $url->setRouteParameter('type', $type);
  }
  if ($id = $formState->get('id')) {
    $url->setRouteParameter('id', $id);
  }
  return $url;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.