Unable to sort by checkbox value

Created on 24 May 2023, almost 2 years ago

Problem/Motivation

I have a webform with a checkbox element. When I create a view, the element can be added as a field or a filter, but it cannot be added to sort by it.

Steps to reproduce

WebformElementViewsAbstract::getViewsData runs this:

    foreach ($this->getElementViewsData($element_plugin, $element) as $k => $v) {
      $v += [
        'webform_id' => $webform->id(),
        'webform_submission_field' => $element['#webform_key'],
      ];
      $data[$table_alias]['webform_submission_value'][$k] = $v;
    }

Since class WebformCheckboxViews extends WebformElementViewsAbstract, WebformCheckboxViews::getElementViewsData adds the WebformElementViewsAbstract's $views_data, which is just the field plugin, and it then adds the checkbox filter plugin. However, no sort plugin is ever added.

Proposed resolution

Change which class is extended.

class WebformCheckboxViews extends WebformDefaultViews {

WebformDefaultViews will add the default sort plugin, along with a filter plugin that is not desired, however WebformCheckboxViews immediately replaces the default filter plugin with its own, so the desired result is achieved.

In addition, it also enables using checkbox values as view arguments, because that couldn't be done before, either.

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Needs review

Version

5.0

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024