How to remove field from form and configuration? We have a custom module, mymodule that has a form, mymoduleForm with two fields: enabled content types and urls. 

We no longer need the enabled content types field on the form and want to remove it from the form and configuration. We do not have either config/install/mymodule.settings.yml and config/schema/mymodule.schema.yml files. 

How can we remove the field (enabled content types) from both the form and configuration?

mymoduleForm.php (all lines below we are thinking need to be removed related to enabled_content_types)

public function buildForm(array $form, FormStateInterface $form_state) {
  $mymodule_config = $this-&gt;config('mymodule.settings');

  $types = \Drupal::entityTypeManager()
    -&gt;getStorage('node_type')
    -&gt;loadMultiple();

  foreach($types as $type) {
    $content_types[$type-&gt;id()] = $type-&gt;label();
  }

  $form['enabled_content_types'] = [
    '#type' =&gt; 'checkboxes', 
    '#title' =&gt; $this-&gt;t('Enabled Content Types'),
    '#description' =&gt; $this-&gt;t('content types .'),
    '#default_value' =&gt; $config-&gt;get('enabled_content_types'),
    '#options' =&gt; $content_types,
  ];

  ...

  return parent::buildForm($form, $form_state);
}

public function submitForm(array &amp;$form, FormStateInterface $form_state) {
  $mymodule_config = $this-&gt;config('mymodule.settings');
  $mymodule_config
    -&gt;set('enabled_content_types', $form_state-&gt;getValue('enabled_content_types'))
    -&gt;set('urls', $form_state-&gt;getValue('urls'))
    -&gt;save();

  parent::submitForm($form, $form_state);
}
change this line

-&gt;set('enabled_content_types', $form_state-&gt;getValue('enabled_content_types')) 


to

-&gt;clear('enabled_content_types')


In Drupal, go to config form and click save. 

Side Note: Alternatively, you could also delete the config via Drupal Console or Drush as mentioned in the answers here, How do I remove a configuration object from the active configuration?

Now you may now remove the relevant code. 

public function buildForm(array $form, FormStateInterface $form_state) {
  $mymodule_config = $this-&gt;config('mymodule.settings');

  $types = \Drupal::entityTypeManager() // remove
    -&gt;getStorage('node_type') // remove
    -&gt;loadMultiple(); // remove

  foreach($types as $type) { // remove
    $content_types[$type-&gt;id()] = $type-&gt;label(); // remove
  } // remove

  $form['enabled_content_types'] = [ // remove
    '#type' =&gt; 'checkboxes', // remove 
    '#title' =&gt; $this-&gt;t('Enabled Content Types'), // remove
    '#description' =&gt; $this-&gt;t('content types .'), // remove
    '#default_value' =&gt; $config-&gt;get('enabled_content_types'), // remove
    '#options' =&gt; $content_types, // remove
  ]; // remove

  ...

  return parent::buildForm($form, $form_state);
}

public function submitForm(array &amp;$form, FormStateInterface $form_state) {
  $mymodule_config = $this-&gt;config('mymodule.settings');
    -&gt;clear('enabled_content_types') // remove
    -&gt;set('urls', $form_state-&gt;getValue('urls'))
    -&gt;save();
  parent::submitForm($form, $form_state);
}