function ViewsFormHelperTrait::buildFormUrl

Same name and namespace in other branches
  1. 11.x core/modules/views/src/ViewsFormHelperTrait.php \Drupal\views\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.

2 calls to ViewsFormHelperTrait::buildFormUrl()
EntityField::buildOptionsForm in core/modules/views/src/Plugin/views/field/EntityField.php
Default option form that provides label widget that all fields should have.
ViewsFormBase::getForm in core/modules/views_ui/src/Form/Ajax/ViewsFormBase.php

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.