Commit 0aa59382 authored by catch's avatar catch

Issue #2192649 by sun, chakrapani, sidharthap: Remove drupal_set_title() from...

Issue #2192649 by sun, chakrapani, sidharthap: Remove drupal_set_title() from installation and update process.
parent 9203c8fd
......@@ -47,42 +47,38 @@ function _batch_page(Request $request) {
// Register database update for the end of processing.
drupal_register_shutdown_function('_batch_shutdown');
$build = array();
// Add batch-specific CSS.
$attached = array('#attached' => array('css' => array()));
foreach ($batch['sets'] as $batch_set) {
if (isset($batch_set['css'])) {
foreach ($batch_set['css'] as $css) {
$attached['#attached']['css'][$css] = array();
$build['#attached']['css'][$css] = array();
}
}
}
drupal_render($attached);
$op = $request->get('op', '');
$output = NULL;
switch ($op) {
case 'start':
case 'do_nojs':
// Display the full progress page on startup and on each additional
// non-JavaScript iteration.
$output = _batch_progress_page();
$current_set = _batch_current_set();
$build['#title'] = $current_set['title'];
$build['content'] = _batch_progress_page();
break;
case 'do':
// JavaScript-based progress page callback.
$output = _batch_do();
break;
case 'do_nojs':
// Non-JavaScript-based progress page.
$output = _batch_progress_page();
break;
return _batch_do();
case 'finished':
$output = _batch_finished();
break;
// _batch_finished() returns a RedirectResponse.
return _batch_finished();
}
return $output;
return $build;
}
/**
......@@ -107,7 +103,6 @@ function _batch_progress_page() {
$batch = &batch_get();
$current_set = _batch_current_set();
drupal_set_title($current_set['title'], PASS_THROUGH);
$new_op = 'do_nojs';
......@@ -128,6 +123,7 @@ function _batch_progress_page() {
$fallback = $current_set['error_message'] . '<br />' . $batch['error_message'];
$fallback = array(
'#theme' => 'maintenance_page',
'#title' => $current_set['title'],
'#content' => $fallback,
'#show_messages' => FALSE,
);
......@@ -195,7 +191,7 @@ function _batch_progress_page() {
),
),
);
return drupal_render($build);
return $build;
}
/**
......
......@@ -218,19 +218,22 @@ function _drupal_log_error($error, $fatal = FALSE) {
}
if ($fatal) {
// Should not translate the string to avoid errors producing more errors.
drupal_set_title('Error');
// We fallback to a maintenance page at this point, because the page generation
// itself can generate errors.
// Should not translate the string to avoid errors producing more errors.
$message = 'The website has encountered an error. Please try again later.';
if ($is_installer) {
// install_display_output() prints the output and ends script execution.
install_display_output($message, $GLOBALS['install_state']);
$output = array(
'#title' => 'Error',
'#markup' => $message,
);
install_display_output($output, $GLOBALS['install_state']);
}
else {
$output = array(
'#theme' => 'maintenance_page',
'#title' => 'Error',
'#content' => $message,
);
$output = drupal_render($output);
......
This diff is collapsed.
......@@ -2437,6 +2437,7 @@ function template_preprocess_maintenance_page(&$variables) {
*/
function template_preprocess_install_page(&$variables) {
template_preprocess_maintenance_page($variables);
$variables['attributes']['class'][] = 'install-page';
// Override the site name that is displayed on the page, since Drupal is
// still in the process of being installed.
$variables['site_name'] = drupal_install_profile_distribution_name();
......@@ -2551,7 +2552,7 @@ function drupal_common_theme() {
'template' => 'maintenance-page',
),
'install_page' => array(
'variables' => array('content' => NULL, 'show_messages' => TRUE),
'variables' => array('content' => NULL, 'show_messages' => TRUE, 'page' => array()),
'template' => 'install-page',
),
'task_list' => array(
......
......@@ -147,7 +147,6 @@ function update_check_requirements($skip_warnings = FALSE) {
// them if the caller has indicated they should be skipped.
if ($severity == REQUIREMENT_ERROR || ($severity == REQUIREMENT_WARNING && !$skip_warnings)) {
update_task_list('requirements');
drupal_set_title('Requirements problem');
$status = array(
'#theme' => 'status_report',
'#requirements' => $requirements,
......@@ -157,6 +156,7 @@ function update_check_requirements($skip_warnings = FALSE) {
drupal_add_http_header('Content-Type', 'text/html; charset=utf-8');
$maintenance_page = array(
'#theme' => 'maintenance_page',
'#title' => 'Requirements problem',
'#content' => $status_report,
);
print drupal_render($maintenance_page);
......
......@@ -44,9 +44,9 @@ public function onKernelRequestMaintenance(GetResponseEvent $event) {
if ($request->attributes->get('_maintenance') != MENU_SITE_ONLINE && !($response instanceof RedirectResponse)) {
// Deliver the 503 page.
drupal_maintenance_theme();
drupal_set_title(t('Site under maintenance'));
$maintenance_page = array(
'#theme' => 'maintenance_page',
'#title' => t('Site under maintenance'),
'#content' => filter_xss_admin(
t(\Drupal::config('system.maintenance')->get('message'), array('@site' => \Drupal::config('system.site')->get('name')))
),
......
......@@ -106,7 +106,7 @@ public function view(FieldItemListInterface $items) {
}
}
$addition[$field_name] = array_merge($info, $elements);
$addition = array_merge($info, $elements);
}
return $addition;
......
......@@ -111,25 +111,21 @@ public function form(FieldItemListInterface $items, array &$form, array &$form_s
// Most widgets need their internal structure preserved in submitted values.
$elements += array('#tree' => TRUE);
$return = array(
$field_name => array(
// Aid in theming of widgets by rendering a classified container.
'#type' => 'container',
// Assign a different parent, to keep the main id for the widget itself.
'#parents' => array_merge($parents, array($field_name . '_wrapper')),
'#attributes' => array(
'class' => array(
'field-type-' . drupal_html_class($this->fieldDefinition->getType()),
'field-name-' . drupal_html_class($field_name),
'field-widget-' . drupal_html_class($this->getPluginId()),
),
return array(
// Aid in theming of widgets by rendering a classified container.
'#type' => 'container',
// Assign a different parent, to keep the main id for the widget itself.
'#parents' => array_merge($parents, array($field_name . '_wrapper')),
'#attributes' => array(
'class' => array(
'field-type-' . drupal_html_class($this->fieldDefinition->getType()),
'field-name-' . drupal_html_class($field_name),
'field-widget-' . drupal_html_class($this->getPluginId()),
),
'#access' => $items->access('edit'),
'widget' => $elements,
),
'#access' => $items->access('edit'),
'widget' => $elements,
);
return $return;
}
/**
......
<?php
/**
* @file
* Contains \Drupal\Core\Installer\Exception\AlreadyInstalledException.
*/
namespace Drupal\Core\Installer\Exception;
use Drupal\Core\StringTranslation\TranslationInterface;
/**
* Exception thrown if Drupal is installed already.
*/
class AlreadyInstalledException extends InstallerException {
/**
* Constructs a new "already installed" exception.
*
* @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
* The string translation manager.
*/
public function __construct(TranslationInterface $string_translation) {
$this->stringTranslation = $string_translation;
$title = $this->t('Drupal already installed');
$message = $this->t('<ul>
<li>To start over, you must empty your existing database, delete your active configuration, and copy <em>default.settings.php</em> over <em>settings.php</em>.</li>
<li>To install to a different database, edit the appropriate <em>settings.php</em> file in the <em>sites</em> folder.</li>
<li>To locate your active configuration, view the appropriate <em>settings.php</em> file in the <em>sites</em> folder.</li>
<li>To upgrade an existing installation, proceed to the <a href="@base-url/core/update.php">update script</a>.</li>
<li>View your <a href="@base-url">existing site</a>.</li>
</ul>', array(
'@base-url' => $GLOBALS['base_url'],
));
parent::__construct($message, $title);
}
}
<?php
/**
* @file
* Contains \Drupal\Core\Installer\Exception\InstallerException.
*/
namespace Drupal\Core\Installer\Exception;
/**
* Base class for exceptions thrown by installer.
*/
class InstallerException extends \RuntimeException {
/**
* The page title to output.
*
* @var string
*/
protected $title;
/**
* The string translation manager.
*
* @var \Drupal\Core\StringTranslation\TranslationInterface
*/
protected $stringTranslation;
/**
* Constructs a new installer exception.
*
* @param string $title
* The page title.
* @param string $message
* (optional) The exception message. Defaults to 'Error'.
* @param int $code
* (optional) The exception code. Defaults to 0.
* @param \Exception $previous
* (optional) A previous exception.
*/
public function __construct($message, $title = 'Error', $code = 0, \Exception $previous = NULL) {
parent::__construct($message, $code, $previous);
$this->title = $title;
}
/**
* Returns the exception page title.
*
* @return string
*/
public function getTitle() {
return $this->title;
}
/**
* Translates a string using StringTranslation.
*
* @see \Drupal\Core\StringTranslation\TranslationInterface::translate()
*/
protected function t($string, array $args = array(), array $options = array()) {
return $this->stringTranslation->translate($string, $args, $options);
}
}
<?php
/**
* @file
* Contains \Drupal\Core\Installer\Exception\NoProfilesException.
*/
namespace Drupal\Core\Installer\Exception;
use Drupal\Core\StringTranslation\TranslationInterface;
/**
* Exception thrown if no installation profiles are available.
*/
class NoProfilesException extends InstallerException {
/**
* Constructs a new "no profiles available" exception.
*
* @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
* The string translation manager.
*/
public function __construct(TranslationInterface $string_translation) {
$this->stringTranslation = $string_translation;
$title = $this->t('No profiles available');
$message = $this->t('We were unable to find any installation profiles. Installation profiles tell us what modules to enable and what schema to install in the database. A profile is necessary to continue with the installation process.');
parent::__construct($message, $title);
}
}
......@@ -230,7 +230,7 @@ public function buildMultiple(array $entities) {
// Then let the formatter build the output for each entity.
foreach ($entities as $key => $entity) {
$items = $entity->get($field_name);
$build[$key] += $formatter->view($items);
$build[$key][$field_name] = $formatter->view($items);
}
}
}
......
......@@ -91,20 +91,13 @@ function field_invoke_method($method, $target_function, EntityInterface $entity,
$target = call_user_func($target_function, $field_definition);
if (method_exists($target, $method)) {
$items = $entity->get($field_definition->getName());
$field_name = $field_definition->getName();
$items = $entity->get($field_name);
$items->filterEmptyItems();
$result = $target->$method($items, $a, $b);
if (isset($result)) {
// For methods with array results, we merge results together.
// For methods with scalar results, we collect results in an array.
if (is_array($result)) {
$return = array_merge($return, $result);
}
else {
$return[] = $result;
}
$return[$field_name] = $result;
}
}
}
......
......@@ -2249,7 +2249,7 @@ function hook_uninstall() {
* installer to pause and display a page to the user by returning any themed
* output that should be displayed on that page (but see below for tasks that
* use the form API or batch API; the return values of these task functions are
* handled differently). You should also use drupal_set_title() within the task
* handled differently). You should also use #title within the task
* callback function to set a custom page title. For some tasks, however, you
* may want to simply do some processing and pass control to the next task
* without ending the page request; to indicate this, simply do not send back
......
......@@ -12,14 +12,14 @@
*/
#}
<!DOCTYPE html>
<html lang="{{ language.langcode }}" dir="{{ language.dir }}">
<html{{ html_attributes }}>
<head>
{{ head }}
<title>{{ head_title }}</title>
{{ styles }}
{{ scripts }}
</head>
<body class="install-page">
<body class="{{ attributes.class }}">
<div class="l-container">
......
......@@ -13,14 +13,14 @@
*/
#}
<!DOCTYPE html>
<html lang="{{ language.langcode }}" dir="{{ language.dir }}" class="install-background">
<html{{ html_attributes }} class="install-background">
<head>
{{ head }}
<title>{{ head_title }}</title>
{{ styles }}
{{ scripts }}
</head>
<body class="install-page">
<body class="{{ attributes.class }}">
<div class="l-container">
......
......@@ -54,13 +54,12 @@ function update_selection_page() {
// Make sure there is no stale theme registry.
\Drupal::cache()->deleteAll();
drupal_set_title('Drupal database update');
$elements = \Drupal::formBuilder()->getForm('Drupal\Core\Update\Form\UpdateScriptSelectionForm');
$output = drupal_render($elements);
$build = \Drupal::formBuilder()->getForm('Drupal\Core\Update\Form\UpdateScriptSelectionForm');
$build['#title'] = 'Drupal database update';
update_task_list('select');
return $output;
return $build;
}
/**
......@@ -98,7 +97,6 @@ function update_flush_all_caches() {
* Displays results of the update script with any accompanying errors.
*/
function update_results_page() {
drupal_set_title('Drupal database update');
update_task_list();
// Report end result.
......@@ -178,7 +176,11 @@ function update_results_page() {
unset($_SESSION['update_results']);
unset($_SESSION['update_success']);
return $output;
$build = array(
'#title' => 'Drupal database update',
'#markup' => $output,
);
return $build;
}
/**
......@@ -199,7 +201,6 @@ function update_info_page() {
$keyvalue->get('update_available_release')->deleteAll();
update_task_list('info');
drupal_set_title('Drupal database update');
$token = drupal_get_token('update');
$output = '<p>Use this utility to update your database whenever a new release of Drupal or a module is installed.</p><p>For more detailed information, see the <a href="http://drupal.org/upgrade">upgrading handbook</a>. If you are unsure what these terms mean you should probably contact your hosting provider.</p>';
$output .= "<ol>\n";
......@@ -212,7 +213,12 @@ function update_info_page() {
$form_action = check_url(drupal_current_script_url(array('op' => 'selection', 'token' => $token)));
$output .= '<form method="post" action="' . $form_action . '"><p><input type="submit" value="Continue" class="form-submit button button-primary" /></p></form>';
$output .= "\n";
return $output;
$build = array(
'#title' => 'Drupal database update',
'#markup' => $output,
);
return $build;
}
/**
......@@ -225,14 +231,19 @@ function update_access_denied_page() {
drupal_add_http_header('Status', '403 Forbidden');
header(\Drupal::request()->server->get('SERVER_PROTOCOL') . ' 403 Forbidden');
watchdog('access denied', 'update.php', NULL, WATCHDOG_WARNING);
drupal_set_title('Access denied');
return '<p>Access denied. You are not authorized to access this page. Log in using either an account with the <em>administer software updates</em> permission or the site maintenance account (the account you created during installation). If you cannot log in, you will have to edit <code>settings.php</code> to bypass this access check. To do this:</p>
$output = '<p>Access denied. You are not authorized to access this page. Log in using either an account with the <em>administer software updates</em> permission or the site maintenance account (the account you created during installation). If you cannot log in, you will have to edit <code>settings.php</code> to bypass this access check. To do this:</p>
<ol>
<li>With a text editor find the settings.php file on your system. From the main Drupal directory that you installed all the files into, go to <code>sites/your_site_name</code> if such directory exists, or else to <code>sites/default</code> which applies otherwise.</li>
<li>There is a line inside your settings.php file that says <code>$settings[\'update_free_access\'] = FALSE;</code>. Change it to <code>$settings[\'update_free_access\'] = TRUE;</code>.</li>
<li>As soon as the update.php script is done, you must change the settings.php file back to its original form with <code>$settings[\'update_free_access\'] = FALSE;</code>.</li>
<li>To avoid having this problem in the future, remember to log in to your website using either an account with the <em>administer software updates</em> permission or the site maintenance account (the account you created during installation) before you backup your database at the beginning of the update process.</li>
</ol>';
$build = array(
'#title' => 'Access denied',
'#markup' => $output,
);
return $build;
}
/**
......@@ -452,9 +463,16 @@ function update_task_list($active = NULL) {
drupal_add_http_header('Content-Type', 'text/html; charset=utf-8');
$maintenance_page = array(
'#theme' => 'maintenance_page',
'#content' => $output,
// $output has to be rendered here, because the maintenance page template
// is not wrapped into the html template, which means that any #attached
// libraries in $output will not be loaded, because the wrapping HTML has
// been printed already.
'#content' => drupal_render($output),
'#show_messages' => !$progress_page,
);
if (isset($output['#title'])) {
$maintenance_page['#page']['#title'] = $output['#title'];
}
print drupal_render($maintenance_page);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment