Issue #2373735 by joelpittet, dawehner: Simplify/clean up BareHtmlPageRenderer

8.0.x
Nathaniel Catchpole 2014-11-20 09:37:59 +00:00
parent 8de9b679a6
commit df19f0b723
9 changed files with 15 additions and 66 deletions

View File

@ -149,7 +149,7 @@ else {
if (!empty($output)) {
$response->headers->set('Content-Type', 'text/html; charset=utf-8');
$response->setContent(\Drupal::service('bare_html_page_renderer')->renderMaintenancePage($output, $page_title, array(
$response->setContent(\Drupal::service('bare_html_page_renderer')->renderBarePage(['#markup' => $output], $page_title, 'maintenance_page', array(
'#show_messages' => $show_messages,
)));
$response->send();

View File

@ -135,7 +135,7 @@ function _batch_progress_page() {
// additional HTML output by PHP shows up inside the page rather than below
// it. While this causes invalid HTML, the same would be true if we didn't,
// as content is not allowed to appear after </html> anyway.
$fallback = \Drupal::service('bare_html_page_renderer')->renderMaintenancePage($fallback, $current_set['title'], array(
$fallback = \Drupal::service('bare_html_page_renderer')->renderBarePage(['#markup' => $fallback], $current_set['title'], 'maintenance_page', array(
'#show_messages' => FALSE,
));
list($fallback) = explode('<!--partial-->', $fallback);

View File

@ -235,7 +235,7 @@ function _drupal_log_error($error, $fatal = FALSE) {
install_display_output($output, $GLOBALS['install_state']);
}
else {
$output = \Drupal::service('bare_html_page_renderer')->renderMaintenancePage($message, 'Error');
$output = \Drupal::service('bare_html_page_renderer')->renderBarePage(['#markup' => $message], 'Error', 'maintenance_page');
}
$response = new Response($output, 500);

View File

@ -933,7 +933,7 @@ function install_display_output($output, $install_state) {
'ETag' => '"' . REQUEST_TIME . '"',
);
$response->headers->add($default_headers);
$response->setContent(\Drupal::service('bare_html_page_renderer')->renderInstallPage($output, $output['#title'], $regions));
$response->setContent(\Drupal::service('bare_html_page_renderer')->renderBarePage($output, $output['#title'], 'install_page', $regions));
$response->send();
exit;
}

View File

@ -133,7 +133,7 @@ class DefaultExceptionSubscriber implements EventSubscriberInterface {
}
$content = $this->t('The website has encountered an error. Please try again later.');
$output = $this->bareHtmlPageRenderer->renderMaintenancePage($content, $this->t('Error'));
$output = $this->bareHtmlPageRenderer->renderBarePage(['#markup' => $content], $this->t('Error'), 'maintenance_page');
$response = new Response($output);
if ($exception instanceof HttpExceptionInterface) {

View File

@ -105,7 +105,7 @@ class MaintenanceModeSubscriber implements EventSubscriberInterface {
$content = Xss::filterAdmin(String::format($this->config->get('system.maintenance')->get('message'), array(
'@site' => $this->config->get('system.site')->get('name'),
)));
$output = $this->bareHtmlPageRenderer->renderMaintenancePage($content, $this->t('Site under maintenance'));
$output = $this->bareHtmlPageRenderer->renderBarePage(['#markup' => $content], $this->t('Site under maintenance'), 'maintenance_page');
$response = new Response($output, 503);
$event->setResponse($response);
}

View File

@ -8,56 +8,19 @@
namespace Drupal\Core\Render;
/**
* Default bare HTML page renderer
* Default bare HTML page renderer.
*/
class BareHtmlPageRenderer implements BareHtmlPageRendererInterface {
/**
* {@inheritdoc}
*/
public function renderMaintenancePage($content, $title, array $page_additions = []) {
if (!is_array($content)) {
$content = ['#markup' => $content];
}
public function renderBarePage(array $content, $title, $page_theme_property, array $page_additions = []) {
$attributes = [
'class' => [
'maintenance-page',
str_replace('_', '-', $page_theme_property),
],
];
return $this->renderBarePage($content, $title, $page_additions, $attributes, 'maintenance_page');
}
/**
* {@inheritdoc}
*/
public function renderInstallPage($content, $title, array $page_additions = []) {
$attributes = [
'class' => [
'install-page',
],
];
return $this->renderBarePage($content, $title, $page_additions, $attributes, 'install_page');
}
/**
* Renders a bare page.
*
* @param string|array $content
* The main content to render in the 'content' region.
* @param string $title
* The title for this maintenance page.
* @param array $page_additions
* Additional regions to add to the page. May also be used to pass the
* #show_messages property for #type 'page'.
* @param array $attributes
* Attributes to set on #type 'html'.
* @param string $page_theme_property
* The #theme property to set on #type 'page'.
*
* @return string
* The rendered HTML page.
*/
protected function renderBarePage(array $content, $title, array $page_additions, array $attributes, $page_theme_property) {
$html = [
'#type' => 'html',
'#attributes' => $attributes,

View File

@ -45,12 +45,14 @@ namespace Drupal\Core\Render;
interface BareHtmlPageRendererInterface {
/**
* Renders a "maintenance" page, styled as such.
* Renders a bare page.
*
* @param string|array $content
* @param array $content
* The main content to render in the 'content' region.
* @param string $title
* The title for this maintenance page.
* @param string $page_theme_property
* The #theme property to set on #type 'page'.
* @param array $page_additions
* Additional regions to add to the page. May also be used to pass the
* #show_messages property for #type 'page'.
@ -58,22 +60,6 @@ interface BareHtmlPageRendererInterface {
* @return string
* The rendered HTML page.
*/
public function renderMaintenancePage($content, $title, array $page_additions = []);
/**
* Renders an "install" page, styled as such.
*
* @param string|array $content
* The main content to render in the 'content' region.
* @param string $title
* The title for this maintenance page.
* @param array $page_additions
* Additional regions to add to the page. May also be used to pass the
* #show_messages property for #type 'page'.
*
* @return string
* The rendered HTML page.
*/
public function renderInstallPage($content, $title, array $page_additions = []);
public function renderBarePage(array $content, $title, $page_theme_property, array $page_additions = []);
}

View File

@ -199,7 +199,7 @@ class DbUpdateController extends ControllerBase {
}
$title = isset($output['#title']) ? $output['#title'] : $this->t('Drupal database update');
return new Response($this->bareHtmlPageRenderer->renderMaintenancePage($output, $title, $regions));
return new Response($this->bareHtmlPageRenderer->renderBarePage($output, $title, 'maintenance_page', $regions));
}
/**