From abbdf7c4c8cd859d72cf403078f462e7bfe5577f Mon Sep 17 00:00:00 2001
From: Marc van Gend <marc@triquanta.nl>
Date: Fri, 27 Jun 2014 14:18:51 +0200
Subject: [PATCH] port form alter and submit handler to new config system

---
 fieldblock.module | 25 ++++++++++++++-----------
 1 file changed, 14 insertions(+), 11 deletions(-)

diff --git a/fieldblock.module b/fieldblock.module
index e377498..373dcff 100644
--- a/fieldblock.module
+++ b/fieldblock.module
@@ -15,10 +15,11 @@ define('FIELDBLOCK_STORAGE_STATIC', 'fieldblock_storage');
 function fieldblock_form_field_ui_display_overview_form_alter(&$form, &$form_state, $form_id) {
   $entity_type = $form['#entity_type'];
   $bundle = $form['#bundle'];
-  $view_mode = $form['#view_mode'];
+  $mode = $form['#mode'];
 
-  $variable_name = 'fieldblock-'. $entity_type .'-'. $bundle .'-'. $view_mode;
-  $settings = variable_get($variable_name, array());
+  $config_name = 'fieldblock.' . $entity_type .'.'. $bundle;
+  $config = \Drupal::config($config_name);
+  $settings = $config->get($mode);
 
   // Add a column header.
   $form['fields']['#header'][] = t('Display as block');
@@ -39,15 +40,17 @@ function fieldblock_form_field_ui_display_overview_form_alter(&$form, &$form_sta
 
 /**
  * Form submit handler for field_ui_display_overview_form.
- * Saves a single variable for each entity + bundle + view mode combination if
- * a field has been made available as block. Having separate variables makes the
- * configuration more flexible for exporting with strongarm and features.
+ * Saves a single config file for each entity + bundle combination if a field in
+ * a certain view mode has been made available as block. Having separate config
+ * files makes the configuration more flexible for exporting and deployment.
  */
 function fieldblock_field_display_submit($form, &$form_state) {
   $entity_type = $form['#entity_type'];
   $bundle = $form['#bundle'];
-  $view_mode = $form['#view_mode'];
-  $variable_name = 'fieldblock-'. $entity_type .'-'. $bundle .'-'. $view_mode;
+  $mode = $form['#mode'];
+
+  $config_name = 'fieldblock.' . $entity_type .'.'. $bundle;
+  $config = \Drupal::config($config_name);
   $settings = array();
 
   foreach ($form_state['values']['fields'] as $field_name => $field) {
@@ -57,11 +60,11 @@ function fieldblock_field_display_submit($form, &$form_state) {
   }
 
   if (empty($settings)) {
-    // This variable may have existed before, so let's clean up a little.
-    variable_del($variable_name);
+    // This config may have existed before, so let's clean up a little.
+    $config->clear($mode)->save();
   }
   else {
-    variable_set($variable_name, $settings);
+    $config->set($mode, $settings)->save();
     drupal_set_message(t('One or more fields have been made available as block. Do not forget to assign the block(s) to a region.'));
   }
 }
-- 
GitLab