function thunder_themes_installed in Thunder 8.2
Same name and namespace in other branches
- 8.5 thunder.profile \thunder_themes_installed()
- 8.3 thunder.profile \thunder_themes_installed()
- 8.4 thunder.profile \thunder_themes_installed()
Implements hook_themes_installed().
File
- ./
thunder.profile, line 130 - Enables modules and site configuration for a thunder site installation.
Code
function thunder_themes_installed($theme_list) {
if (in_array('infinite', $theme_list)) {
$configFactory = \Drupal::configFactory();
$configs = $configFactory
->listAll('block.block.infinite_');
foreach ($configs as $config) {
$configFactory
->getEditable($config)
->delete();
}
\Drupal::service('module_installer')
->install([
'infinite_article',
], TRUE);
// Ensure that footer block is pre-filled with lazy loading block.
$entityTypeManager = \Drupal::service('entity_type.manager');
$articles = $entityTypeManager
->getStorage('node')
->loadByProperties([
'type' => 'article',
]);
$actionManager = \Drupal::service('plugin.manager.action');
$resetFooterAction = $actionManager
->createInstance('node_reset_footer_blocks_action');
$resetHeaderAction = $actionManager
->createInstance('node_reset_footer_blocks_action');
foreach ($articles as $article) {
$resetFooterAction
->execute($article);
$resetHeaderAction
->execute($article);
}
// Adding header and footer blocks to default article view.
/** @var \Drupal\Core\Entity\Entity\EntityViewDisplay $display */
$display = entity_get_display('node', 'article', 'default');
$display
->setComponent('field_header_blocks', [
'type' => 'entity_reference_entity_view',
'label' => 'hidden',
'settings' => [
'view_mode' => 'default',
],
'weight' => -1,
])
->setComponent('field_footer_blocks', [
'type' => 'entity_reference_entity_view',
'label' => 'hidden',
'settings' => [
'view_mode' => 'default',
],
'weight' => 2,
])
->save();
$display
->save();
$profilePath = drupal_get_path('profile', 'thunder');
$configFactory
->getEditable('infinite.settings')
->set('logo.use_default', FALSE)
->set('logo.path', $profilePath . '/themes/thunder_base/images/Thunder-white_400x90.png')
->set('favicon.use_default', FALSE)
->set('favicon.path', $profilePath . '/themes/thunder_base/favicon.ico')
->save(TRUE);
// Set default pages.
$configFactory
->getEditable('system.site')
->set('page.front', '/taxonomy/term/1')
->save(TRUE);
// Set infinite image styles and gallery view mode.
$configFactory
->getEditable('core.entity_view_display.media.image.default')
->set('content.field_image.settings.image_style', 'inline_m')
->set('content.field_image.settings.responsive_image_style', '')
->save(TRUE);
$configFactory
->getEditable('core.entity_view_display.media.gallery.default')
->set('content.field_media_images.settings.view_mode', 'gallery')
->save(TRUE);
}
if (in_array('thunder_amp', $theme_list)) {
// Install AMP module.
\Drupal::service('module_installer')
->install([
'amp',
], TRUE);
\Drupal::configFactory()
->getEditable('amp.settings')
->set('amp_library_process_full_html', TRUE)
->save(TRUE);
// Set AMP theme to thunder_amp,
// if not set, or is one of the included themes.
$ampThemeConfig = \Drupal::configFactory()
->getEditable('amp.theme');
$ampTheme = $ampThemeConfig
->get('amptheme');
if (empty($ampTheme) || $ampTheme == 'ampsubtheme_example' || $ampTheme == 'amptheme') {
$ampThemeConfig
->set('amptheme', 'thunder_amp')
->save(TRUE);
}
// Disable unused blocks.
/** @var \Drupal\block\Entity\Block[] $blocks */
$blocks = Block::loadMultiple([
'thunder_amp_account_menu',
'thunder_amp_breadcrumbs',
'thunder_amp_footer',
'thunder_amp_local_actions',
'thunder_amp_local_tasks',
'thunder_amp_main_menu',
'thunder_amp_messages',
'thunder_amp_tools',
]);
foreach ($blocks as $block) {
$block
->disable()
->save();
}
}
if (in_array('amptheme', $theme_list)) {
\Drupal::service('module_installer')
->install([
'amp',
], TRUE);
}
}