From 6787141f4abbe05fa488c869087596588e15c9d0 Mon Sep 17 00:00:00 2001
From: "Frederic G. MARAND" <fgm@osinet.fr>
Date: Sun, 19 Apr 2015 10:16:18 +0200
Subject: [PATCH] Issue #2407593: applied multiple Form API core changes.

- form state are now a classed object
- list controllers are now list builders.
---
 config_readonly.module |   34 +++++++++++++++++++++-------------
 1 file changed, 21 insertions(+), 13 deletions(-)

diff --git a/config_readonly.module b/config_readonly.module
index 3ae451a..d030a98 100644
--- a/config_readonly.module
+++ b/config_readonly.module
@@ -1,27 +1,30 @@
 <?php
 
+use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
 use Drupal\Core\Form\ConfigFormBase;
-use Drupal\Core\Entity\EntityFormControllerInterface;
+use Drupal\Core\Entity\EntityFormInterface;
 use Drupal\Core\Config\Entity\ConfigEntityInterface;
-use Drupal\Core\Config\Entity\ConfigEntityListController;
+use Drupal\Core\Form\FormStateInterface;
+use Drupal\Core\Site\Settings;
 
 /**
  * Implements hook_form_alter().
  */
-function config_readonly_form_alter(array &$form, array &$form_state) {
+function config_readonly_form_alter(array &$form, FormStateInterface &$form_state) {
   // If settings.php doesn't say to lock config changes, then don't do anything.
-  if (!settings()->get('config_readonly')) {
+  if (!Settings::get('config_readonly')) {
     return;
   }
 
-  // Check if the form is a ConfigFormBase or a ConfigEntityListController.
-  $form_object = $form_state['build_info']['callback_object'];
-  $is_config_form = $form_object instanceof ConfigFormBase || $form_object instanceof ConfigEntityListController;
+  // Check if the form is a ConfigFormBase or a ConfigEntityListBuilder.
+  $build_info = $form_state->getBuildInfo();
+  $form_object = $build_info['callback_object'];
+  $is_config_form = $form_object instanceof ConfigFormBase || $form_object instanceof ConfigEntityListBuilder;
 
-  // Check if the form is an EntityFormControllerInterface and if the entity is
-  // a config entity.
-  if (!$is_config_form && isset($form_state['controller']) && $form_state['controller'] instanceof EntityFormControllerInterface) {
-    $is_config_form = $form_state['controller']->getEntity() instanceof ConfigEntityInterface;
+  // Check if the form is an EntityFormInterface and entity is a config entity.
+  if (!$is_config_form && $form_object instanceof EntityFormInterface) {
+    $entity = $form_object->getEntity();
+    $is_config_form = $entity instanceof ConfigEntityInterface;
   }
 
   // Display a message informing the user that this form cannot be saved.
@@ -33,7 +36,12 @@ function config_readonly_form_alter(array &$form, array &$form_state) {
 
 /**
  * Helper validation function that always returns false.
+ *
+ * @param array $form
+ *   A build form array.
+ * @param \Drupal\Core\Form\FormStateInterface $form_state
+ *   The form state.
  */
-function _config_readonly_validate_failure(array $form, array &$form_state) {
-  \Drupal::formBuilder()->setErrorByName(NULL, $form_state, t('This configuration form cannot be saved because the configuration active store is read-only.'));
+function _config_readonly_validate_failure(array $form, FormStateInterface &$form_state) {
+  $form_state->setErrorByName(NULL, t('This configuration form cannot be saved because the configuration active store is read-only.'));
 }
-- 
1.7.9.5

