Create fields programmatically via content type settings 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(&amp;$form, &amp;$form_state){
$form['new_option'] = array(
    '#type' =&gt; 'details',
    '#title' =&gt; t('NEW OPTION'),
    '#group' =&gt; 'additional_settings',
);

$form['new_option']['new_option_options'] = array(
    '#type' =&gt; 'checkbox',
    '#title' =&gt; t('Create fields'),
    '#collapsible' =&gt; TRUE,
    '#collapsed' =&gt; TRUE,
    '#weight' =&gt; 10,
);
}


But how can I save the value of the checkbox in config and use it as default_value.
Thanks Clive, I ended up using the following code to set and get the config settings.

function module_name_form_node_type_form_alter(&amp;$form)
{
    //get node type
    $bundle = $form['type']['#default_value'];
    $node_type = NodeType::load($bundle);

    //create vertical tab
    $form['new_option'] = array(
        '#type' =&gt; 'details',
        '#title' =&gt; t('New option'),
        '#group' =&gt; 'additional_settings',
    );

    //add checkbox to vertical tab
    $form['new_option']['new_option_options'] = array(
        '#type' =&gt; 'checkbox',
        '#title' =&gt; t('New option checkbox'),
        '#collapsible' =&gt; TRUE,
        '#collapsed' =&gt; TRUE,
        '#weight' =&gt; 10,
        '#default_value' =&gt; $node_type-&gt;getThirdPartySetting('new_option','new_option_options'),
    );

    //create submit handler
    $form['actions']['submit']['#submit'][] = 'module_name_form_submit';
}

function module_name_form_submit(&amp;$form)
{
    //get node type
    $bundle = $form['type']['#default_value'];
    $node_type = NodeType::load($bundle);

    //set checkbox value to config and save
    $node_type-&gt;setThirdPartySetting('new_option','new_option_options',$form['new_option']['new_option_options']['#value']);
    $node_type-&gt;save();

   //enable/disable fields
}