jfu-1.0.x-dev/modules/jfu_usage/src/Form/JfuUsageFiltersForm.php

modules/jfu_usage/src/Form/JfuUsageFiltersForm.php
<?php

namespace Drupal\jfu_usage\Form;

use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;

/**
 *
 * @package Drupal\jfu_usage\Form
 */
class JfuUsageFiltersForm extends FormBase {

  /**
   * {@inheritDoc}
   */
  public function getFormId() {
    return 'jfu_usage_filters';
  }

  /**
   * {@inheritDoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $params = $this->getRequest()->query->all();
    $form['key_value'] = [
      '#type' => 'textfield',
      '#title' => $this->t('Search by key value'),
      '#default_value' => !empty($params['key_value']) ? $params['key_value'] : '',
      '#description' => $this->t('To find the exact way consider entering the string you want in quotes, for example: <strong>"simple_card"</strong>.'),
    ];

    $form['actions'] = [
      '#type' => 'actions',
    ];

    $form['actions']['submit'] = [
      '#type' => 'submit',
      '#value' => $this->t('Apply'),
    ];

    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public function validateForm(array &$form, FormStateInterface $form_state) {}

  /**
  * {@inheritdoc}
  */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $request = $this->getRequest();
    $variant_id = $form_state->getValue('key_value');
    $query_params = [
      'query' => [
        'key_value' => $variant_id
      ],
    ];
    $url = Url::createFromRequest($request);
    $url->setOptions($query_params);
    $form_state->setRedirectUrl($url);
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc