I have created a Config Entity, one of the values it stores is the results from a set of checkboxes. This is the element in the form
$form['choices'] = [ '#type' => 'checkboxes', '#title' => $this->t('Choices'), '#default_value' => $this->entity->getChoices() ?: , '#options' => $this->choicesManager->getAsOptions(), ];
In the choices.schema.yml I have this:
choices: type: sequence sequence: type: string
And it works EXCEPT I always get an mbstring warning when saving the entity:
Warning: mb_strlen() expects parameter 1 to be string, array given in Drupal\Core\Form\FormValidator->performRequiredValidation() (line 333 of /shore_site/web/core/lib/Drupal/Core/Form/FormValidator.php).
Because it's a warning, it disappears after a moment (but you can see, for a moment, that the array in question contains the selected items from this element). And the config entity has been saved correctly:
choices: choice_1: choice_1 choice_2: choice_2 choice_3: '0' choice_4: '0'
There's more to the config entity, of course, and by removing this item the error goes away. So it's definitely this.
I have other config files where I've saved checkboxes painlessly, but they haven't been config entities. (And I have other config entities that work fine, but aren't trying to save checkboxes.)
I've tried various different ways of defining this in the schema (including using the "undefined" type) but the warning keeps coming up.
(I've looked at other answers, only one talks about the same problem and that person ended up serialising the checkbox data. I don't want to do that.)
I'm tearing my hair out - can you help me save my hair?