I want to make a module to create custom fields to a content type. But I want to be able to turn the fields on and off via the content type edit page.
So I want to add a tab to the vertical tab part at the bottom of the content type edit page where I have a single on off checkbox. When selected and saved, fields are created. When not selected the fields will be removed (or not created).
I created the option in the node type form. By using this:
function HOOK_form_node_type_form_alter(&$form, &$form_state){
$form['new_option'] = array(
'#type' => 'details',
'#title' => t('NEW OPTION'),
'#group' => 'additional_settings',
);
$form['new_option']['new_option_options'] = array(
'#type' => 'checkbox',
'#title' => t('Create fields'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#weight' => 10,
);
}
But how can I save the value of the checkbox in config and use it as default_value.
$node_type->getThirdPartySettings()
, and in the submit handler$node_type->setThirdPartySettings()
to save – Clive♦ Jan 5 '19 at 19:49