Drupal 8 - ConfigFormBase and overrides caution

Submitted by superadmin on Sun, 12/27/2015 - 18:04

Drupal 8 makes a good attempt to stop overrides provided in places like settings.php from bleeding into configuration forms that will be exported. By default config objects obtained from Drupal::config can contain overrides from settings.php. However in the config object returned by ConfigFormBase::config() overrides are disabled and the data fetched from this object are the raw configurations. This could be dangerous when you want toggle between configuration between dev environment and production i.e. setting the site email address to a development inbox.

Drupal 8 - system settings form

Submitted by superadmin on Sun, 12/27/2015 - 15:22

system_settings_form was a handy function in Drupal 7 that saved forms to variables. This has been replaced by ConfigFormBase in Drupal 8. 

If we want the same behavior in Drupal 8 that was present in system_settings_form, our form class must extend ConfigFormBase. In doing so we must implement the abstract getEditableConfigNames method which returns the config names which are editable.

Also our buildForm method should call it's parent buildForm so that the submit buttons can be added.