So I'm working on developing module and one of the things the module does is create a field in certain content types. This field is a boolean (type: list_boolean) but what I'm trying to do is to get it so the default widget is the single radio button rather than the list radio button. Here is my code as of now:
<?PHP
function mcc_notify_enable() {
// Check if our field is not already created.
if (!field_info_field('notify_emailb')) {
$field = array(
'field_name' => 'notify_emailb',
'type' => 'list_boolean',
'settings' =>
array(
'label' => 'Notify opt-ins',
'description' => 'blah blah',
)
,
);
field_create_field($field);
// Create the instance on the bundle.
$instance = array(
'field_name' => 'notify_emailb',
'entity_type' => 'node',
'label' => 'Notify opt-ins',
'description' => 'blah blah',
// If you don't set the "required" property then the field wont be required by default.
'required' => TRUE,
'bundle' => 'article',
'widget' => array(
'type' => 'list_boolean',
),
);
field_create_instance($instance);
}
}
?>
I know that there is a 'default widget' property in the field_create_field function. However, I don't know the machine name of the widget I want. Where would I go to find that information? I've searched the docs and even searched the database but came up with nothing. What is the machine name for field type boolean, widget type "Single on/off checkbox"? You'd think this information would be easy to find.
Comments
Single on/off widget machine name
Not sure of all the machine names, but I believe the machine name for a single radio button is:
'options_onoff' -- when using it in the widget array of the field info
'optionwidgets_onoff' -- when using it as the value of the 'widget_type' key in the field info.
But how can you find out the
But how can you find out the widget_type in general. This is a page that shows a lot in my google searches, so might be a good idea to get some extra info on this page. Info page https://www.drupal.org/docs/7/api/form-api/forms-api-modify-form-widgets... is not very helpful (or working for Drupal 8)
You need to look at the
You need to look at the plugin class of the widget. This will be the ID value in the code comments for the class.
Great, thanks.
Thanks @jaypan. With your hint I was able to find the id in /geolocation/src/Plugin/Field/FieldWidget/GeolocationGooglegeocoderWidget.php