Skip to content
Snippets Groups Projects
Unverified Commit a424345c authored by briancanini's avatar briancanini Committed by GitHub
Browse files

Merge pull request #606 from ASCWebServices/mobile_device_detection

apply mobile_device_detection uninstall hook patch
parents a884c988 e60bed19
No related branches found
No related tags found
No related merge requests found
......@@ -8,7 +8,8 @@
/**
* Implements hook_install().
*/
function mobile_device_detection_install() {
function mobile_device_detection_install()
{
// Enable mobile_device_detection plugin.
$config = \Drupal::service('config.factory')->getEditable('views.settings');
$display_extenders = $config->get('display_extenders') ?: [];
......@@ -20,14 +21,61 @@ function mobile_device_detection_install() {
/**
* Implements hook_uninstall().
*/
function mobile_device_detection_uninstall() {
function mobile_device_detection_uninstall()
{
// Load config factory service
$config_factory = \Drupal::configFactory();
// Disable mobile_device_detection plugin.
$config = \Drupal::service('config.factory')->getEditable('views.settings');
$display_extenders = $config->get('display_extenders') ?: [];
$key = array_search('mobile_device_detection', $display_extenders);
if ($key !== FALSE) {
unset($display_extenders[$key]);
$config->set('display_extenders', $display_extenders);
$config->save();
$views_config = $config_factory->getEditable('views.settings');
$display_extenders = $views_config->get('display_extenders') ?: [];
$plugin_key = array_search('mobile_device_detection', $display_extenders);
if ($plugin_key !== FALSE) {
unset($display_extenders[$plugin_key]);
$views_config->set('display_extenders', $display_extenders);
$views_config->save();
}
// Initialize an array to track modified blocks
$modified_blocks = [];
// Iterate through all blocks and remove dependencies and visibility conditions
foreach ($config_factory->listAll('block.block.') as $config_name) {
$config = $config_factory->getEditable($config_name);
$block_modified = FALSE;
// Check and update module dependencies
$dependencies = $config->get('dependencies');
if (isset($dependencies['module'])) {
$module_key = array_search('mobile_device_detection', $dependencies['module']);
if ($module_key !== FALSE) {
unset($dependencies['module'][$module_key]);
$dependencies['module'] = array_values($dependencies['module']);
$config->set('dependencies', $dependencies);
$block_modified = TRUE;
}
}
// Check and remove visibility conditions
$visibility = $config->get('visibility');
if (isset($visibility['mobile_device_detection_condition_plugin'])) {
unset($visibility['mobile_device_detection_condition_plugin']);
$config->set('visibility', $visibility);
$block_modified = TRUE;
}
// Save config if it was modified
if ($block_modified) {
$config->save();
$modified_blocks[] = $config_name;
}
}
// Log a message if any blocks were modified
if (!empty($modified_blocks)) {
\Drupal::logger('mobile_device_detection')->notice('The mobile_device_detection module was uninstalled and modified the following blocks: @blocks. Please check that these blocks are behaving correctly.', ['@blocks' => implode(', ', $modified_blocks)]);
} else {
\Drupal::logger('mobile_device_detection')->notice('The mobile_device_detection module was uninstalled successfully without modifying any blocks.');
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment