get('theme');
if (!empty($theme)) {
// Get current list of themes.
$themes = list_themes();
// Check if the specified theme is one recognized by the system.
if (!empty($themes[$theme])) {
// Enable the theme if it is currently disabled.
if (empty($themes[$theme]->status)) {
theme_enable(array($theme));
}
// Set the default theme.
\Drupal::config('system.theme')
->set('default', $theme)
->save();
// Rebuild the menu. This duplicates the menu_router_rebuild() in
// theme_enable(). However, modules must know the current default theme in
// order to use this information in hook_menu() or hook_menu_alter()
// implementations, and doing the variable_set() before the theme_enable()
// could result in a race condition where the theme is default but not
// enabled.
\Drupal::service('router.builder')->rebuild();
menu_router_rebuild();
\Drupal::cache('cache')->deleteTags(array('local_task' => 1));
// The status message depends on whether an admin theme is currently in use:
// a value of 0 means the admin theme is set to be the default theme.
$admin_theme = \Drupal::config('system.theme')->get('admin');
if ($admin_theme != 0 && $admin_theme != $theme) {
drupal_set_message(t('Please note that the administration theme is still set to the %admin_theme theme; consequently, the theme on this page remains unchanged. All non-administrative sections of the site, however, will show the selected %selected_theme theme by default.', array(
'%admin_theme' => $themes[$admin_theme]->info['name'],
'%selected_theme' => $themes[$theme]->info['name'],
)));
}
else {
drupal_set_message(t('%theme is now the default theme.', array('%theme' => $themes[$theme]->info['name'])));
}
}
else {
drupal_set_message(t('The %theme theme was not found.', array('%theme' => $theme)), 'error');
}
return new RedirectResponse(url('admin/appearance', array('absolute' => TRUE)));
}
throw new AccessDeniedHttpException();
}
/**
* Recursively check compatibility.
*
* @param $incompatible
* An associative array which at the end of the check contains all
* incompatible files as the keys, their values being TRUE.
* @param $files
* The set of files that will be tested.
* @param $file
* The file at which the check starts.
* @return
* Returns TRUE if an incompatible file is found, NULL (no return value)
* otherwise.
*/
function _system_is_incompatible(&$incompatible, $files, $file) {
if (isset($incompatible[$file->name])) {
return TRUE;
}
// Recursively traverse required modules, looking for incompatible modules.
foreach ($file->requires as $requires) {
if (isset($files[$requires]) && _system_is_incompatible($incompatible, $files, $files[$requires])) {
$incompatible[$file->name] = TRUE;
return TRUE;
}
}
}
/**
* Returns HTML for an administrative block for display.
*
* @param $variables
* An associative array containing:
* - block: An array containing information about the block:
* - show: A Boolean whether to output the block. Defaults to FALSE.
* - title: The block's title.
* - content: (optional) Formatted content for the block.
* - description: (optional) Description of the block. Only output if
* 'content' is not set.
*
* @ingroup themeable
*/
function theme_admin_block($variables) {
$block = $variables['block'];
$output = '';
// Don't display the block if it has no content to display.
if (empty($block['show'])) {
return $output;
}
$output .= '
';
if (!empty($block['title'])) {
$output .= '
' . $block['title'] . '
';
}
if (!empty($block['content'])) {
$output .= '
' . render($block['content']) . '
';
}
else {
$output .= '
' . $block['description'] . '
';
}
$output .= '
';
return $output;
}
/**
* Returns HTML for the content of an administrative block.
*
* @param $variables
* An associative array containing:
* - content: An array containing information about the block. Each element
* of the array represents an administrative menu item, and must at least
* contain the keys 'title', 'href', and 'localized_options', which are
* passed to l(). A 'description' key may also be provided.
*
* @ingroup themeable
*/
function theme_admin_block_content($variables) {
$content = $variables['content'];
$output = '';
if (!empty($content)) {
$class = 'admin-list';
if ($compact = system_admin_compact_mode()) {
$class .= ' compact';
}
$output .= '
';
if (!$compact && isset($item['description'])) {
$output .= '
' . filter_xss_admin($item['description']) . '
';
}
}
$output .= '
';
}
return $output;
}
/**
* Returns HTML for an administrative page.
*
* @param $variables
* An associative array containing:
* - blocks: An array of blocks to display. Each array should include a
* 'title', a 'description', a formatted 'content' and a 'position' which
* will control which container it will be in. This is usually 'left' or
* 'right'.
*
* @ingroup themeable
*/
function theme_admin_page($variables) {
$blocks = $variables['blocks'];
$stripe = 0;
$container = array();
foreach ($blocks as $block) {
$admin_block = array(
'#theme' => 'admin_block',
'#block' => $block,
);
if ($block_output = drupal_render($admin_block)) {
if (empty($block['position'])) {
// perform automatic striping.
$block['position'] = ++$stripe % 2 ? 'left' : 'right';
}
if (!isset($container[$block['position']])) {
$container[$block['position']] = '';
}
$container[$block['position']] .= $block_output;
}
}
$system_compact_link = array('#theme' => 'system_compact_link');
$output = '
';
return $output;
}
/**
* Returns HTML for the status report.
*
* This theme function is dependent on install.inc being loaded, because
* that's where the constants are defined.
*
* @param $variables
* An associative array containing:
* - requirements: An array of requirements/status items. Each requirement
* is an associative array containing the following elements:
* - title: The name of the requirement.
* - value: (optional) The current value (version, time, level, etc).
* - description: (optional) The description of the requirement.
* - severity: (optional) The requirement's result/severity level, one of:
* - REQUIREMENT_INFO: Status information.
* - REQUIREMENT_OK: The requirement is satisfied.
* - REQUIREMENT_WARNING: The requirement failed with a warning.
* - REQUIREMENT_ERROR: The requirement failed with an error.
*
* @ingroup themeable
*/
function theme_status_report($variables) {
$requirements = $variables['requirements'];
$severities = array(
REQUIREMENT_INFO => array(
'title' => t('Info'),
'class' => 'info',
),
REQUIREMENT_OK => array(
'title' => t('OK'),
'class' => 'ok',
),
REQUIREMENT_WARNING => array(
'title' => t('Warning'),
'class' => 'warning',
),
REQUIREMENT_ERROR => array(
'title' => t('Error'),
'class' => 'error',
),
);
$output = '
';
$output .= '
' . t('Status') . '
' . t('Component') . '
' . t('Details') . '
';
$output .= '
';
foreach ($requirements as $requirement) {
// Always use the explicit requirement severity, if defined. Otherwise,
// default to REQUIREMENT_OK in the installer to visually confirm that
// installation requirements are met. And default to REQUIREMENT_INFO to
// denote neutral information without special visualization.
if (isset($requirement['severity'])) {
$severity = $severities[(int) $requirement['severity']];
}
elseif (defined('MAINTENANCE_MODE') && MAINTENANCE_MODE == 'install') {
$severity = $severities[REQUIREMENT_OK];
}
else {
$severity = $severities[REQUIREMENT_INFO];
}
// hook_requirements does not require value to be set. Set to null if not:
if (isset($requirement['value'])) {
$value = $requirement['value'];
}
else {
$value = NULL;
}
$severity['icon'] = '
' . $severity['title'] . '
';
// Output table rows.
$output .= '
';
$output .= '
' . $severity['icon'] . '
';
$output .= '
' . $requirement['title'] . '
';
$output .= '
' . $value;
if (!empty($requirement['description'])) {
$output .= '
' . $requirement['description'] . '
';
}
$output .= '
';
}
$output .= '
';
return $output;
}
/**
* Returns HTML for the modules form.
*
* @param $variables
* An associative array containing:
* - form: A render element representing the form.
*
* @ingroup themeable
*/
function theme_system_modules_details($variables) {
$form = $variables['form'];
// Individual table headers.
$rows = array();
// Iterate through all the modules, which are children of this element.
foreach (element_children($form) as $key) {
// Stick the key into $module for easier access.
$module = $form[$key];
// Create the row for the table.
$row = array();
// Add the checkbox into the first cell.
unset($module['enable']['#title']);
$module['#requires'] = array_filter($module['#requires']);
$module['#required_by'] = array_filter($module['#required_by']);
$requires = !empty($module['#requires']);
$required_by = !empty($module['#required_by']);
$version = !empty($module['version']['#markup']);
$row[] = array('class' => array('checkbox'), 'data' => drupal_render($module['enable']));
// Add the module label and expand/collapse functionalty.
$col2 = '';
$row[] = array('class' => array('module'), 'data' => $col2);
// Add the description, along with any modules it requires.
$description = '';
if ($version || $requires || $required_by) {
$description .= '
';
}
/**
* Returns HTML for a table of currently disabled modules.
*
* @param $variables
* An associative array containing:
* - form: A render element representing the form.
*
* @ingroup themeable
*/
function theme_system_modules_uninstall($variables) {
$form = $variables['form'];
// No theming for the confirm form.
if (isset($form['confirm'])) {
return drupal_render($form);
}
// Table headers.
$header = array(t('Uninstall'),
t('Name'),
t('Description'),
);
// Display table.
$rows = array();
foreach (element_children($form['modules']) as $module) {
if (!empty($form['modules'][$module]['#required_by'])) {
$disabled_message = format_plural(count($form['modules'][$module]['#required_by']),
'To uninstall @module, the following module must be uninstalled first: @required_modules',
'To uninstall @module, the following modules must be uninstalled first: @required_modules',
array('@module' => $form['modules'][$module]['#module_name'], '@required_modules' => implode(', ', $form['modules'][$module]['#required_by'])));
$disabled_message = '
' . $disabled_message . '
';
}
else {
$disabled_message = '';
}
$rows[] = array(
array('data' => drupal_render($form['uninstall'][$module]), 'align' => 'center'),
'',
array('data' => drupal_render($form['modules'][$module]['description']) . $disabled_message, 'class' => array('description')),
);
}
$table = array(
'#theme' => 'table',
'#header' => $header,
'#rows' => $rows,
'#empty' => t('No modules are available to uninstall.'),
);
$output = drupal_render($table);
$output .= drupal_render_children($form);
return $output;
}
/**
* Returns HTML for the Appearance page.
*
* @param $variables
* An associative array containing:
* - theme_groups: An associative array containing groups of themes.
* - theme_group_titles: An associative array containing titles of themes.
*
* @ingroup themeable
*/
function theme_system_themes_page($variables) {
$theme_groups = $variables['theme_groups'];
$output = '
';
foreach ($variables['theme_group_titles'] as $state => $title) {
if (!count($theme_groups[$state])) {
// Skip this group of themes if no theme is there.
continue;
}
// Start new theme group.
$output .= '
' . t('This theme requires PHP version @php_required and is incompatible with PHP version !php_version.', array('@php_required' => $theme->info['php'], '!php_version' => phpversion())) . '