at_tools-8.x-3.x-dev/at_theme_generator/at_theme_generator.install
at_theme_generator/at_theme_generator.install
<?php
/**
* @file
* AT Theme Generator install file.
*/
use Drupal\at_theme_generator\File\DirectoryOperations;
/**
* Implements hook_install().
*/
function at_theme_generator_install() {
$list_info = \Drupal::service('theme_handler')->listInfo();
$theme = 'at_generator';
// Check if the old at_generator is installed.
if (array_key_exists($theme, $list_info)) {
// Check if the old generator theme is default, if so replace with Bartik.
// Users sometimes made the mistake of setting the old generator theme as
// default which totally borks their site, we use this module install to
// to try and fix that issue for them.
if ($theme == \Drupal::service('theme_handler')->getDefault()) {
\Drupal::service('theme_handler')->setDefault('bartik');
\Drupal::messenger()->addStatus(t('Bartik set as default theme.'));
}
// Now uninstall it.
\Drupal::service('theme_installer')->uninstall([$theme]);
}
// Now remove the old generator theme.
$gen_path = \Drupal::service('extension.list.theme')->getPath($theme);
if (!empty($gen_path)) {
$directoryOperations = new DirectoryOperations();
$directoryOperations->directoryRemove($gen_path);
\Drupal::messenger()->addStatus(t('Old at_generator theme has been removed, please use the new Theme Generator tab in Appearance settings.'));
}
}
/**
* Assign "administer at_theme_generator" permission to roles currently assigned the "administer themes" permission.
*/
function at_theme_generator_update_8001() {
if ($roles = user_roles(FALSE, 'administer themes')) {
foreach ($roles as $rid => $role) {
user_role_grant_permissions($rid, ['administer at_theme_generator']);
}
}
}
