Score:0

When providing default settings for elements in a field widget, what is the syntax for multiple value checkboxes?

cn flag

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();
}
cn flag
It’s simply an array of the keys which correspond to the checkboxes you want to be checked
thiokol avatar
cn flag
Thank you Clive, I was overthinking this when I couldnt find examples, works perfectly :)
Score:1
cn flag

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();
  }
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.