CshsOption could not be converted to string when populating a CshsElement form element

Created on 30 May 2024, 29 days ago

Problem/Motivation

The following error appears when populating a CshsElement form element.

TypeError: Drupal\cshs\Component\CshsOption::__construct(): Argument #1 ($label) must be of type string, Drupal\cshs\Component\CshsOption given, called in /app/web/modules/contrib/cshs/src/Element/CshsElement.php on line 92 in Drupal\cshs\Component\CshsOption->__construct() (line 22 of modules/contrib/cshs/src/Component/CshsOption.php).

Steps to reproduce

foreach($terms as $term){
        $cshc_options[$term->id()] = new CshsOption($term->label(), $term->parent->target_id);
}
$form['term_list'] = [
    '#type' => CshsElement::ID,
    '#label' => 'Term list',
    '#required' => TRUE,
    '#label_attributes' => ['class' =>['form-required js-form-required']],
    '#none_value' => null,
    '#force_deepest' => true,
    '#options' => $cshc_options,
];

Proposed resolution

The patch in https://www.drupal.org/project/cshs/issues/3449705#comment-15610645 πŸ› CshsOption could not be converted to string when using Better Exposed Filters Needs review fixes the problem.

πŸ› Bug report
Status

Active

Version

4.0

Component

Code

Created by

πŸ‡«πŸ‡·France lizuka

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

Comments & Activities

Production build 0.69.0 2024