0

I have a field widget with three different settings, two of them are just string values but the third is multiple checkboxes.

This page describes how to set default settings, simple enough for integer or string and single value fields, but I'm not sure how to set default values for some of the checkboxes in the multiple checkbox element.

Below is the function where i need to set some of the values in the multiple checkboxes element to true. I can just put 'checkboxes_element' => '', as a default value which makes them all unticked, but i need to set some of those checkboxes as true for the default value.

/**
 * {@inheritdoc}
 */
 public static function defaultSettings() {
  return [
    // Create the custom setting 'size', and
    // assign a default value of 60
    'size' => 60,
  ] + parent::defaultSettings();
}
2
  • 1
    It’s simply an array of the keys which correspond to the checkboxes you want to be checked
    – Clive
    Aug 25, 2023 at 19:39
  • Thank you Clive, I was overthinking this when I couldnt find examples, works perfectly :) Aug 25, 2023 at 19:58

1 Answer 1

1

Thanks to Clive, much easier than I was expecting, the default settings function should just look like the following, replacing the options in the array with the relevant keys:

 public static function defaultSettings() {
    return [
      'checkboxes_options' => array('option1', 'option5', 'option9'),
    ] + parent::defaultSettings();
  }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.