From d8e7b2c7f020e9f270258afcc84edc9a5d84dba9 Mon Sep 17 00:00:00 2001
From: iposadat <ismael.posada.trobo@cern.ch>
Date: Thu, 28 Jun 2018 10:02:47 +0200
Subject: [PATCH] Memcache module disabled from the Uninstall modules admin
 page.

---
 cern_integration.module | 31 ++++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)

diff --git a/cern_integration.module b/cern_integration.module
index 4fb782d..d3906e0 100644
--- a/cern_integration.module
+++ b/cern_integration.module
@@ -1,9 +1,38 @@
 <?php
 
+/* Debugging purposes */
 //function cern_integration_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
-   //drupal_set_message(t("Form ID: $form_id"), "status");
+//   drupal_set_message(t("Form ID: $form_id"), "status");
 //}
 
+//function cern_integration_form_menu_edit_item_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
+//   drupal_set_message(t("Form ID: $form_id"), "status");
+//}
+/* Debugging purposes */
+
+/**
+* Implements hook_form_FORM_ID_alter() for system_modules_uninstall().
+* Checks whether memcache module exists. If so, disable the possibility of uninstalling it. It's mandatory to have it installed.
+*/
+function cern_integration_form_system_modules_uninstall_alter(&$form, &$form_state, $form_id){
+    $moduleHandler = \Drupal::service('module_handler');
+    if ($moduleHandler->moduleExists('memcache')){
+        $form['uninstall']['memcache']['#disabled'] = TRUE;
+
+        global $base_url;
+        $memcache_setup_link = \Drupal\Core\Link::fromTextAndUrl('Memcache Setup', \Drupal\Core\Url::fromUri("$base_url/_site/memcache.php"))->toString();
+
+        $txt = '</br>';
+        $txt .= '<em>Please, do not uninstall memcache module since it can break down your site.</em>';
+        $txt .= '</br>';
+        $txt .= "<em>If you do not want to use it, please go to " . $memcache_setup_link . ".</em>";
+
+        $form['modules']['memcache']['description']['memcache_warning'] = array(
+            '#markup' => t($txt)
+        );
+    }
+}
+
 /**
  * Implements hook_update_projects_alter().
  * Remove Drupal core as well as all centrally managed modules and themes from the Update manager.
-- 
GitLab