2

In the baseFieldDefinitions method of my custom entity, I see I can provide a checkbox list with code like...

$fields['my_field'] = BaseFieldDefinition::create("list_string")
      ->setSetting('allowed_values', $$my_options)
      ->setLabel('My Field')
      ->setRequired(FALSE)
      ->setCardinality(-1)
      ->setDisplayOptions('form', array(
        'type' => 'options_buttons',
        'weight' => 5
      ))
      ->setDisplayConfigurable('form', TRUE)
      ->setDisplayConfigurable('view', TRUE);

But how would I specify radio buttons so the user can make only one selection from the list?

3

The radios/checkboxes are displayed based on the field's cardinality:

  • If the field can store more than one (e.g., unlimited: ->setCardinality(-1), or 2,3,etc. ->setCardinality(2), ->setCardinality(3), etc.), it will be displayed as checkboxes.
  • If the field can store only one (i.e. ->setCardinality(1)), it will be displayed as radio buttons.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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