Skip to content
Snippets Groups Projects
Commit 66699c25 authored by bucefal91's avatar bucefal91
Browse files

Issue #2928231 by bucefal91: Improving UX of radios filter when it is exposed.

parent f26342c4
No related branches found
Tags 7.x-1.0-beta3
No related merge requests found
......@@ -131,6 +131,7 @@ class WebformSubmissionFieldFilter extends StringFilter {
// Swap the type of value if the current operator dictates doing so.
if (isset($operator_definition['webform_views_element_type']) && $operator_definition['webform_views_element_type'] != self::ELEMENT_TYPE) {
$element['#type'] = $operator_definition['webform_views_element_type'];
unset($element['#options']);
}
// Wrap the value with a container that will be used for AJAX.
......
<?php
namespace Drupal\webform_views\Plugin\views\filter;
use Drupal\Component\Utility\Html;
use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\ElementInfoManagerInterface;
use Drupal\views\Plugin\views\filter\StringFilter;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Filter for 'radios' webform elements.
*
* @ViewsFilter("webform_submission_radios_filter")
*/
class WebformSubmissionRadiosFilter extends WebformSubmissionFieldFilter {
/**
* {@inheritdoc}
*/
protected function exposedTranslate(&$form, $type) {
$type = $form['#type'];
parent::exposedTranslate($form, $type);
if ($form['#type'] == 'select' && $form['#type'] != $type) {
$form['#theme_wrappers'][] = 'form_element';
}
}
}
<?php
namespace Drupal\webform_views\WebformElementViews;
use Drupal\Component\Utility\Html;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\webform\Plugin\WebformElementInterface;
use Drupal\webform\WebformInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Webform views handler for radios webform elements.
*/
class WebformRadiosViews extends WebformDefaultViews {
/**
* {@inheritdoc}
*/
public function getElementViewsData(WebformElementInterface $element_plugin, array $element) {
$views_data = parent::getElementViewsData($element_plugin, $element);
$views_data['filter'] = [
'id' => 'webform_submission_radios_filter',
'real field' => 'value',
];
return $views_data;
}
}
......@@ -68,6 +68,10 @@ function webform_views_webform_element_info_alter(array &$elements) {
$views_handler = \Drupal\webform_views\WebformElementViews\WebformCheckboxViews::class;
break;
case 'radios':
$views_handler = \Drupal\webform_views\WebformElementViews\WebformRadiosViews::class;
break;
case 'date':
$views_handler = \Drupal\webform_views\WebformElementViews\WebformDateViews::class;
break;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment