class ViewsExposedForm in Zircon Profile 8
Same name in this branch
- 8 core/modules/views/src/Form/ViewsExposedForm.php \Drupal\views\Form\ViewsExposedForm
- 8 core/modules/views/src/Annotation/ViewsExposedForm.php \Drupal\views\Annotation\ViewsExposedForm
Same name and namespace in other branches
- 8.0 core/modules/views/src/Form/ViewsExposedForm.php \Drupal\views\Form\ViewsExposedForm
Provides the views exposed form.
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\views\Form\ViewsExposedForm
Expanded class hierarchy of ViewsExposedForm
File
- core/
modules/ views/ src/ Form/ ViewsExposedForm.php, line 20 - Contains \Drupal\views\Form\ViewsExposedForm.
Namespace
Drupal\views\FormView source
class ViewsExposedForm extends FormBase {
/**
* The exposed form cache.
*
* @var \Drupal\views\ExposedFormCache
*/
protected $exposedFormCache;
/**
* Constructs a new ViewsExposedForm
*
* @param \Drupal\views\ExposedFormCache $exposed_form_cache
* The exposed form cache.
*/
public function __construct(ExposedFormCache $exposed_form_cache) {
$this->exposedFormCache = $exposed_form_cache;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('views.exposed_form_cache'));
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'views_exposed_form';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
// Don't show the form when batch operations are in progress.
if ($batch = batch_get() && isset($batch['current_set'])) {
return array(
// Set the theme callback to be nothing to avoid errors in template_preprocess_views_exposed_form().
'#theme' => '',
);
}
// Make sure that we validate because this form might be submitted
// multiple times per page.
$form_state
->setValidationEnforced();
/** @var \Drupal\views\ViewExecutable $view */
$view = $form_state
->get('view');
$display =& $form_state
->get('display');
$form_state
->setUserInput($view
->getExposedInput());
// Let form plugins know this is for exposed widgets.
$form_state
->set('exposed', TRUE);
// Check if the form was already created
if ($cache = $this->exposedFormCache
->getForm($view->storage
->id(), $view->current_display)) {
return $cache;
}
$form['#info'] = array();
// Go through each handler and let it generate its exposed widget.
foreach ($view->display_handler->handlers as $type => $value) {
/** @var \Drupal\views\Plugin\views\ViewsHandlerInterface $handler */
foreach ($view->{$type} as $id => $handler) {
if ($handler
->canExpose() && $handler
->isExposed()) {
// Grouped exposed filters have their own forms.
// Instead of render the standard exposed form, a new Select or
// Radio form field is rendered with the available groups.
// When an user choose an option the selected value is split
// into the operator and value that the item represents.
if ($handler
->isAGroup()) {
$handler
->groupForm($form, $form_state);
$id = $handler->options['group_info']['identifier'];
}
else {
$handler
->buildExposedForm($form, $form_state);
}
if ($info = $handler
->exposedInfo()) {
$form['#info']["{$type}-{$id}"] = $info;
}
}
}
}
$form['actions'] = array(
'#type' => 'actions',
);
$form['actions']['submit'] = array(
// Prevent from showing up in \Drupal::request()->query.
'#name' => '',
'#type' => 'submit',
'#value' => $this
->t('Apply'),
'#id' => Html::getUniqueId('edit-submit-' . $view->storage
->id()),
);
$form['#action'] = $view
->hasUrl() ? $view
->getUrl()
->toString() : Url::fromRoute('<current>')
->toString();
$form['#theme'] = $view
->buildThemeFunctions('views_exposed_form');
$form['#id'] = Html::cleanCssIdentifier('views_exposed_form-' . $view->storage
->id() . '-' . $display['id']);
/** @var \Drupal\views\Plugin\views\exposed_form\ExposedFormPluginBase $exposed_form_plugin */
$exposed_form_plugin = $view->display_handler
->getPlugin('exposed_form');
$exposed_form_plugin
->exposedFormAlter($form, $form_state);
// Save the form.
$this->exposedFormCache
->setForm($view->storage
->id(), $view->current_display, $form);
return $form;
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
$view = $form_state
->get('view');
foreach (array(
'field',
'filter',
) as $type) {
/** @var \Drupal\views\Plugin\views\ViewsHandlerInterface[] $handlers */
$handlers =& $view->{$type};
foreach ($handlers as $key => $handler) {
$handlers[$key]
->validateExposed($form, $form_state);
}
}
/** @var \Drupal\views\Plugin\views\exposed_form\ExposedFormPluginBase $exposed_form_plugin */
$exposed_form_plugin = $view->display_handler
->getPlugin('exposed_form');
$exposed_form_plugin
->exposedFormValidate($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
foreach (array(
'field',
'filter',
) as $type) {
/** @var \Drupal\views\Plugin\views\ViewsHandlerInterface[] $handlers */
$handlers =& $form_state
->get('view')->{$type};
foreach ($handlers as $key => $info) {
$handlers[$key]
->submitExposed($form, $form_state);
}
}
$view = $form_state
->get('view');
$view->exposed_data = $form_state
->getValues();
$view->exposed_raw_input = [];
$exclude = array(
'submit',
'form_build_id',
'form_id',
'form_token',
'exposed_form_plugin',
'reset',
);
/** @var \Drupal\views\Plugin\views\exposed_form\ExposedFormPluginBase $exposed_form_plugin */
$exposed_form_plugin = $view->display_handler
->getPlugin('exposed_form');
$exposed_form_plugin
->exposedFormSubmit($form, $form_state, $exclude);
foreach ($form_state
->getValues() as $key => $value) {
if (!in_array($key, $exclude)) {
$view->exposed_raw_input[$key] = $value;
}
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
FormBase:: |
protected | property | The config factory. | 3 |
FormBase:: |
protected | property | The logger factory. | |
FormBase:: |
protected | property | The request stack. | 1 |
FormBase:: |
protected | property | The route match. | |
FormBase:: |
protected | function | Retrieves a configuration object. | |
FormBase:: |
protected | function | Gets the config factory for this form. | 3 |
FormBase:: |
private | function | Returns the service container. | |
FormBase:: |
protected | function | Gets the current user. | |
FormBase:: |
protected | function | Gets the request object. | |
FormBase:: |
protected | function | Gets the route match. | |
FormBase:: |
protected | function | Gets the logger for a specific channel. | |
FormBase:: |
public | function | Resets the configuration factory. | |
FormBase:: |
public | function | Sets the config factory for this form. | |
FormBase:: |
public | function | Sets the request stack object to use. | |
LinkGeneratorTrait:: |
protected | property | The link generator. | 1 |
LinkGeneratorTrait:: |
protected | function | Returns the link generator. | |
LinkGeneratorTrait:: |
protected | function | Renders a link to a route given a route name and its parameters. | |
LinkGeneratorTrait:: |
public | function | Sets the link generator service. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
StringTranslationTrait:: |
protected | property | The string translation service. | |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
UrlGeneratorTrait:: |
protected | property | The url generator. | |
UrlGeneratorTrait:: |
protected | function | Returns the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Returns a redirect response object for the specified route. | |
UrlGeneratorTrait:: |
public | function | Sets the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. | |
ViewsExposedForm:: |
protected | property | The exposed form cache. | |
ViewsExposedForm:: |
public | function |
Form constructor. Overrides FormInterface:: |
|
ViewsExposedForm:: |
public static | function |
Instantiates a new instance of this class. Overrides FormBase:: |
|
ViewsExposedForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
ViewsExposedForm:: |
public | function |
Form submission handler. Overrides FormInterface:: |
|
ViewsExposedForm:: |
public | function |
Form validation handler. Overrides FormBase:: |
|
ViewsExposedForm:: |
public | function | Constructs a new ViewsExposedForm |