diff --git a/core/modules/system/system.install b/core/modules/system/system.install index d2c1b40..acb227f 100644 --- a/core/modules/system/system.install +++ b/core/modules/system/system.install @@ -5,6 +5,7 @@ * Install, update and uninstall functions for the system module. */ +use Drupal\block\Entity\Block; use Drupal\Component\Utility\Crypt; use Drupal\Component\Utility\Environment; use Drupal\Component\Utility\SafeMarkup; @@ -1087,9 +1088,172 @@ function system_schema() { } /** + * @addtogroup updates-8.0.0-beta + * @{ + */ + +/** * Change the index on the {router} table. */ function system_update_8001() { db_drop_index('router', 'pattern_outline_fit'); db_add_index('router', 'pattern_outline_parts', array('pattern_outline', 'number_parts')); } + +/** + * Create local actions and tasks blocks. + */ +function system_update_8002() { + /** @var \Drupal\Core\Extension\ModuleHandler $module_handler */ + $module_handler = \Drupal::service('module_handler'); + // Nothing we can do if block module is not installed. + if (!$module_handler->moduleExists('block')) { + return \Drupal::translation()->translate('Block module is not enabled so local actions and tasks which have been converted to blocks, are not visible anymore.'); + } + + /** @var \Drupal\Core\Extension\ThemeHandler $theme_handler */ + $theme_handler = \Drupal::service('theme_handler'); + $config_factory = \Drupal::configFactory(); + $custom_themes_installed = FALSE; + $message = NULL; + + $local_actions_default_settings = [ + 'plugin' => 'system_local_actions_block', + 'region' => 'content', + 'label' => 'Primary admin actions', + 'visibility' => [], + 'weight' => 0, + 'label_display' => 0, + 'cache' => [ + 'max_age' => 0, + ], + ]; + $tabs_default_settings = [ + 'plugin' => 'system_tabs_block', + 'region' => 'content', + 'label' => 'Tabs', + 'visibility' => [], + 'weight' => 0, + 'label_display' => 0, + 'cache' => [ + 'max_age' => 0, + ], + ]; + foreach ($theme_handler->listInfo() as $theme) { + if ($theme->getName() == 'bartik') { + if (!$config_factory->get('block.block.bartik_local_actions')) { + $values = [ + 'id' => 'bartik_local_actions', + 'theme' => 'bartik', + 'weight' => -20, + ] + $local_actions_default_settings; + $block = Block::create($values); + $block->save(); + } + + if (!$config_factory->get('block.block.bartik_tabs')) { + $values = [ + 'id' => 'bartik_tabs', + 'theme' => 'bartik', + 'weight' => -30, + ] + $tabs_default_settings; + $block = Block::create('block', $values); + $block->save(); + } + } + elseif ($theme->getName() == 'seven') { + if (!$config_factory->get('block.block.seven_local_actions')) { + $values = [ + 'id' => 'seven_local_actions', + 'theme' => 'seven', + 'weight' => -10, + ] + $local_actions_default_settings; + $block = Block::create($values); + $block->save(); + } + + if (!$config_factory->get('block.block.seven_primary_tabs')) { + $values = [ + 'region' => 'header', + 'id' => 'seven_primary_tabs', + 'theme' => 'seven', + 'label' => 'Primary tabs', + 'settings' => [ + 'primary' => TRUE, + 'secondary' => FALSE, + ], + ] + $tabs_default_settings; + $block = Block::create($values); + $block->save(); + } + + if (!$config_factory->get('block.block.seven_secondary_tabs')) { + $values = [ + 'region' => 'pre_content', + 'id' => 'seven_secondary_tabs', + 'theme' => 'seven', + 'label' => 'Secondary tabs', + 'settings' => [ + 'primary' => FALSE, + 'secondary' => TRUE, + ], + ] + $tabs_default_settings; + $block = Block::create($values); + $block->save(); + } + } + elseif ($theme->getName() == 'stark') { + if (!$config_factory->get('block.block.stark_local_actions')) { + $values = [ + 'id' => 'stark_local_actions', + 'theme' => 'stark', + ] + $local_actions_default_settings; + $block = Block::create($values); + $block->save(); + } + + if (!$config_factory->get('block.block.stark_tabs')) { + $values = [ + 'id' => 'stark_tabs', + 'theme' => 'stark', + ] + $tabs_default_settings; + $block = Block::create('block', $values); + $block->save(); + } + } + elseif ($theme->getName() == 'classy') { + // Don't place any blocks or trigger custom themes installed warning. + } + else { + $custom_themes_installed = TRUE; + if (!$config_factory->get(sprintf('block.block.%s_local_actions'))) { + $values = [ + 'id' => sprintf('%s_local_actions', $theme_name), + 'theme' => $theme->getName(), + 'weight' => -10, + ] + $local_actions_default_settings; + $block = Block::create($values); + $block->save(); + } + if (!$config_factory->get(sprintf('block.block.%s_tabs'))) { + $values = [ + 'id' => sprintf('%s_tabs', $theme->name), + 'theme' => $theme->getName(), + 'weight' => -20, + ] + $tabs_default_settings; + $block = Block::create($values); + $block->save(); + } + } + } + + if ($custom_themes_installed) { + $message = \Drupal::translation()->translate('Because your site has custom theme(s) installed We have fallbacked to set the local actions and tasks blocks into content region. Please manually review the block configurations and remove the removed variables from your templates.'); + } + + return $message; +} + +/** + * @} End of "addtogroup updates-8.0.0-beta". + */