farmOS/modules/core/ui/theme/farm_ui_theme.install

97 lines
3.0 KiB
PHP

<?php
/**
* @file
* Install, update and uninstall functions for the farm_ui_theme module.
*/
use Drupal\block\Entity\Block;
/**
* Implements hook_install().
*/
function farm_ui_theme_install() {
// Install the Gin theme and make it the default.
\Drupal::service('theme_installer')->install(['gin']);
\Drupal::configFactory()->getEditable('system.theme')->set('default', 'gin')->save();
// Load Gin settings.
$gin_settings = \Drupal::configFactory()->getEditable('gin.settings');
// Use vertical toolbar.
$gin_settings->set('classic_toolbar', 'vertical');
// Use green/orange color palette.
$gin_settings->set('preset_accent_color', 'green');
$gin_settings->set('preset_focus_color', 'orange');
// Use farmOS logo and favicon.
$path = \Drupal::service('extension.list.module')->getPath('farm_ui_theme');
$gin_settings->set('logo.use_default', FALSE);
$gin_settings->set('logo.path', $path . '/logo.png');
$gin_settings->set('favicon.use_default', FALSE);
$gin_settings->set('favicon.path', $path . '/favicon.ico');
// Save Gin settings.
$gin_settings->save();
// Create the "Powered by farmOS" block.
// This must be done in hook_install() instead of config/install because Gin
// needs to be installed first.
$values = [
'id' => 'farm_powered',
'plugin' => 'farm_powered_by_block',
'theme' => 'gin',
'region' => 'content',
'weight' => 1000,
'settings' => [
'id' => 'farm_powered_by_block',
'label' => t('Powered by farmOS'),
'provider' => 'farm_ui_theme',
'label_display' => '0',
],
'visibility' => [],
'dependencies' => [
'enforced' => [
'module' => [
'farm_ui_theme',
],
],
],
];
Block::create($values)->save();
// Modify the block.block.gin_local_actions config to use our class.
$local_actions_block = \Drupal::configFactory()->getEditable('block.block.gin_local_actions');
$local_actions_block->set('plugin', 'farm_local_actions_block');
$local_actions_block->set('settings.id', 'farm_local_actions_block');
$local_actions_block->set('settings.provider', 'farm_ui_theme');
$local_actions_block->save();
}
/**
* Implements hook_uninstall().
*/
function farm_ui_theme_uninstall() {
// Revert changes to block.block.gin_local_actions config.
$local_actions_block = \Drupal::configFactory()->getEditable('block.block.gin_local_actions');
$local_actions_block->set('plugin', 'local_actions_block');
$local_actions_block->set('settings.id', 'local_actions_block');
$local_actions_block->set('settings.provider', 'core');
$local_actions_block->save();
}
/**
* Update Gin theme logo settings.
*/
function farm_ui_theme_update_9000(&$sandbox) {
$gin_settings = \Drupal::configFactory()->getEditable('gin.settings');
$gin_settings->set('logo.use_default', $gin_settings->get('icon_default'));
$gin_settings->clear('icon_default');
$gin_settings->set('logo.path', $gin_settings->get('icon_path'));
$gin_settings->clear('icon_path');
$gin_settings->save();
}