hasUrl example

$executable->setExposedInput($exposed_input);

      if (!$executable->setDisplay($display_id)) {
        return [
          '#markup' => t('Invalid display id @display', ['@display' => $display_id]),
        ];
      }

      $executable->setArguments($args);

      // Store the current view URL for later use:       if ($executable->hasUrl() && $executable->display_handler->getOption('path')) {
        $path = $executable->getUrl();
      }

      // Make view links come back to preview.
      // Also override the current path so we get the pager, and make sure the       // Request object gets all of the proper values from $_SERVER.       $request = Request::createFromGlobals();
      $request->attributes->set(RouteObjectInterface::ROUTE_NAME, 'entity.view.preview_form');
      $request->attributes->set(RouteObjectInterface::ROUTE_OBJECT, \Drupal::service('router.route_provider')->getRouteByName('entity.view.preview_form'));
      $request->attributes->set('view', $this->storage);
      
    // Form ID. Base form ID should only be added when different.     if ($this->getBaseFormId() !== $this->getFormId()) {
      $form_state->addBuildInfo('base_form_id', $this->getBaseFormId());
    }

    $form = [];

    $query = $this->requestStack->getCurrentRequest()->query->all();
    $query = UrlHelper::filterQueryParameters($query['_wrapper_format', 'ajax_page_state'], '');

    $options = ['query' => $query];
    $form['#action'] = $view->hasUrl() ? $view->getUrl()->setOptions($options)->toString() : Url::fromRoute('<current>')->setOptions($options)->toString();
    // Tell the preprocessor whether it should hide the header, footer, pager,     // etc.     $form['show_view_elements'] = [
      '#type' => 'value',
      '#value' => ($step == 'views_form_views_form') ? TRUE : FALSE,
    ];

    $form_object = $this->getFormObject($form_state);
    $form += $form_object->buildForm($form$form_state$view$output);

    return $form;
  }
$form['actions'] = [
      '#type' => 'actions',
    ];
    $form['actions']['submit'] = [
      // Prevent from showing up in \Drupal::request()->query.       '#name' => '',
      '#type' => 'submit',
      '#value' => $this->t('Apply'),
      '#id' => Html::getUniqueId('edit-submit-' . $view->storage->id()),
    ];

    if (!$view->hasUrl()) {
      // On any non views.ajax route, use the current route for the form action.       if ($this->getRouteMatch()->getRouteName() !== 'views.ajax') {
        $form_action = Url::fromRoute('<current>')->toString();
      }
      else {
        // On the views.ajax route, set the action to the page we were on.         $form_action = Url::fromUserInput($this->currentPathStack->getPath())->toString();
      }
    }
    else {
      $form_action = $view->getUrl()->toString();
    }
Home | Imprint | This part of the site doesn't use cookies.