Problem/Motivation
CSHS filters will crash the page when configured to use exposed filter widgets from BEF.
Steps to reproduce
1. Create a View (page display) of nodes with an entity reference field pointing to a taxonomy.
2. Configure the view to have a filter on that taxonomy entity reference field. Use CSHS on this filter.
3. Configure Exposed Form to use Better Exposed Filters.
4. In the exposed form settings, configure the field's filter settings to use either "Links" or "Checkboxes/Radio Buttons".
5. Save the exposed form options and view.
6. View the view.
On step 5, you'll see the first hints of the issue with an error.
On step 6, the page will crash with the following error:
Error: Object of class Drupal\cshs\Component\CshsOption could not be converted to string in Drupal\better_exposed_filters\BetterExposedFiltersHelper::flattenOptions() (line 131 of modules/contrib/better_exposed_filters/src/BetterExposedFiltersHelper.php).
The issue lies in BEF's BetterExposedFiltersHelper::flattenOptions()
which expects the typical Select render element options. Since CSHS replaces option values with the CshsOption
object, BEF's flattenOptions
falls into the last case (id as key, label as value), where the option value is coerced to a string. CshsOption
currently cannot be coerced to a string.
Proposed resolution
Could be done in two ways:
- Allow CshsOption
to be coerced into a string by returning the label. This is the quick-n-dirty way, to conform with BEF's logic.
- Refactor CshsOption
so that it conforms to the object case of the Select render element (object with an options property). I believe this is "The Right Way" since we already the CshsOption
instance.
Remaining tasks
- Review
- Test
User interface changes
- None.
API changes
- Potential change to CshsOption
's properties.
Data model changes
- Potential change to CshsOption
's properties.