diff --git a/core/modules/block/lib/Drupal/block/BlockFormController.php b/core/modules/block/lib/Drupal/block/BlockFormController.php
index b70575df54c1bce27d4eeef61462c762ee9ac4bc..08bf090aebef9be9dc6d26637844f9fed69432f4 100644
--- a/core/modules/block/lib/Drupal/block/BlockFormController.php
+++ b/core/modules/block/lib/Drupal/block/BlockFormController.php
@@ -93,6 +93,13 @@ public static function create(ContainerInterface $container) {
*/
public function form(array $form, array &$form_state) {
$entity = $this->entity;
+
+ // Store theme settings in $form_state for use below.
+ if (!$theme = $entity->get('theme')) {
+ $theme = $this->configFactory->get('system.theme')->get('default');
+ }
+ $form_state['block_theme'] = $theme;
+
$form['#tree'] = TRUE;
$form['settings'] = $entity->getPlugin()->buildConfigurationForm(array(), $form_state);
@@ -226,10 +233,10 @@ public function form(array $form, array &$form_state) {
);
// Theme settings.
- if ($theme = $entity->get('theme')) {
+ if ($entity->get('theme')) {
$form['theme'] = array(
'#type' => 'value',
- '#value' => $entity->get('theme'),
+ '#value' => $theme,
);
}
else {
@@ -239,7 +246,6 @@ public function form(array $form, array &$form_state) {
$theme_options[$theme_name] = $theme_info->info['name'];
}
}
- $theme = $this->configFactory->get('system.theme')->get('default');
$form['theme'] = array(
'#type' => 'select',
'#options' => $theme_options,
@@ -251,6 +257,7 @@ public function form(array $form, array &$form_state) {
),
);
}
+
// Region settings.
$form['region'] = array(
'#type' => 'select',
diff --git a/core/modules/block/lib/Drupal/block/Tests/BlockStorageUnitTest.php b/core/modules/block/lib/Drupal/block/Tests/BlockStorageUnitTest.php
index d9cb5b10a1f16f8d0508d335a3cdb0a62453c0dc..36ed74a5c01d5139d9d43fbbbf3d0210fda8be2d 100644
--- a/core/modules/block/lib/Drupal/block/Tests/BlockStorageUnitTest.php
+++ b/core/modules/block/lib/Drupal/block/Tests/BlockStorageUnitTest.php
@@ -139,12 +139,12 @@ protected function renderTests() {
$expected[] = ' ';
$expected[] = '';
$expected[] = '
';
- $expected[] = ' ';
- $expected[] = '
';
+ $expected[] = ' ';
+ $expected[] = ' ';
$expected[] = '';
$expected[] = '';
$expected_output = implode("\n", $expected);
- $this->assertEqual(drupal_render($output), $expected_output, 'The block rendered correctly.');
+ $this->assertEqual(drupal_render($output), $expected_output);
// Reset the HTML IDs so that the next render is not affected.
drupal_static_reset('drupal_html_id');
@@ -167,12 +167,12 @@ protected function renderTests() {
$expected[] = ' ';
$expected[] = '';
$expected[] = ' ';
- $expected[] = ' ';
- $expected[] = '
';
+ $expected[] = ' ';
+ $expected[] = ' ';
$expected[] = '';
$expected[] = '';
$expected_output = implode("\n", $expected);
- $this->assertEqual(drupal_render($output), $expected_output, 'The block rendered correctly.');
+ $this->assertEqual(drupal_render($output), $expected_output);
// Clean up this entity.
$entity->delete();
}
diff --git a/core/modules/block/lib/Drupal/block/Tests/BlockSystemBrandingTest.php b/core/modules/block/lib/Drupal/block/Tests/BlockSystemBrandingTest.php
new file mode 100644
index 0000000000000000000000000000000000000000..192d8fcd0ebb6fce5b2a8783cf2dda0f05f98da9
--- /dev/null
+++ b/core/modules/block/lib/Drupal/block/Tests/BlockSystemBrandingTest.php
@@ -0,0 +1,120 @@
+ 'System Branding Block',
+ 'description' => 'Tests branding block display.',
+ 'group' => 'Block',
+ );
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function setUp() {
+ parent::setUp();
+ // Set a site slogan.
+ \Drupal::config('system.site')
+ ->set('slogan', 'Community plumbing')
+ ->save();
+ // Add the system branding block to the page.
+ $this->drupalPlaceBlock('system_branding_block', array('region' => 'header', 'id' => 'site-branding'));
+ }
+
+ /**
+ * Tests system branding block configuration.
+ */
+ public function testSystemBrandingSettings() {
+ $site_logo_xpath = '//div[@id="block-site-branding"]//a[@class="site-logo"]';
+ $site_name_xpath = '//div[@id="block-site-branding"]//div[@class="site-name"]';
+ $site_slogan_xpath = '//div[@id="block-site-branding"]//div[@class="site-slogan"]';
+
+ // Set default block settings.
+ $this->drupalGet('');
+ $site_logo_element = $this->xpath($site_logo_xpath);
+ $site_name_element = $this->xpath($site_name_xpath);
+ $site_slogan_element = $this->xpath($site_slogan_xpath);
+ // Test that all branding elements are displayed.
+ $this->assertTrue(!empty($site_logo_element), 'The branding block logo was found.');
+ $this->assertTrue(!empty($site_name_element), 'The branding block site name was found.');
+ $this->assertTrue(!empty($site_slogan_element), 'The branding block slogan was found.');
+
+ // Turn just the logo off.
+ \Drupal::config('block.block.site-branding')
+ ->set('settings.use_site_logo', 0)
+ ->save();
+ $this->drupalGet('');
+ $site_logo_element = $this->xpath($site_logo_xpath);
+ $site_name_element = $this->xpath($site_name_xpath);
+ $site_slogan_element = $this->xpath($site_slogan_xpath);
+ // Re-test all branding elements.
+ $this->assertTrue(empty($site_logo_element), 'The branding block logo was disabled.');
+ $this->assertTrue(!empty($site_name_element), 'The branding block site name was found.');
+ $this->assertTrue(!empty($site_slogan_element), 'The branding block slogan was found.');
+
+ // Turn just the site name off.
+ \Drupal::config('block.block.site-branding')
+ ->set('settings.use_site_logo', 1)
+ ->set('settings.use_site_name', 0)
+ ->save();
+ $this->drupalGet('');
+ $site_logo_element = $this->xpath($site_logo_xpath);
+ $site_name_element = $this->xpath($site_name_xpath);
+ $site_slogan_element = $this->xpath($site_slogan_xpath);
+ // Re-test all branding elements.
+ $this->assertTrue(!empty($site_logo_element), 'The branding block logo was found.');
+ $this->assertTrue(empty($site_name_element), 'The branding block site name was disabled.');
+ $this->assertTrue(!empty($site_slogan_element), 'The branding block slogan was found.');
+
+ // Turn just the site slogan off.
+ \Drupal::config('block.block.site-branding')
+ ->set('settings.use_site_name', 1)
+ ->set('settings.use_site_slogan', 0)
+ ->save();
+ $this->drupalGet('');
+ $site_logo_element = $this->xpath($site_logo_xpath);
+ $site_name_element = $this->xpath($site_name_xpath);
+ $site_slogan_element = $this->xpath($site_slogan_xpath);
+ // Re-test all branding elements.
+ $this->assertTrue(!empty($site_logo_element), 'The branding block logo was found.');
+ $this->assertTrue(!empty($site_name_element), 'The branding block site name was found.');
+ $this->assertTrue(empty($site_slogan_element), 'The branding block slogan was disabled.');
+
+ // Turn the site name and the site slogan off.
+ \Drupal::config('block.block.site-branding')
+ ->set('settings.use_site_name', 0)
+ ->set('settings.use_site_slogan', 0)
+ ->save();
+ $this->drupalGet('');
+ $site_logo_element = $this->xpath($site_logo_xpath);
+ $site_name_element = $this->xpath($site_name_xpath);
+ $site_slogan_element = $this->xpath($site_slogan_xpath);
+ // Re-test all branding elements.
+ $this->assertTrue(!empty($site_logo_element), 'The branding block logo was found.');
+ $this->assertTrue(empty($site_name_element), 'The branding block site name was disabled.');
+ $this->assertTrue(empty($site_slogan_element), 'The branding block slogan was disabled.');
+ }
+
+}
diff --git a/core/modules/block/templates/block.html.twig b/core/modules/block/templates/block.html.twig
index 14c7330286088b0a3c9fdbaa97da8c72c8739692..3c51d46fde95922013efa4fe97b50e5f28823c16 100644
--- a/core/modules/block/templates/block.html.twig
+++ b/core/modules/block/templates/block.html.twig
@@ -49,6 +49,8 @@
{{ title_suffix }}
- {{ content }}
+ {% block content %}
+ {{ content }}
+ {% endblock %}
diff --git a/core/modules/system/lib/Drupal/system/Plugin/Block/SystemBrandingBlock.php b/core/modules/system/lib/Drupal/system/Plugin/Block/SystemBrandingBlock.php
new file mode 100644
index 0000000000000000000000000000000000000000..0b3213902711aff88a9b43c362ee13b8f6038a92
--- /dev/null
+++ b/core/modules/system/lib/Drupal/system/Plugin/Block/SystemBrandingBlock.php
@@ -0,0 +1,203 @@
+configFactory = $config_factory;
+ $this->urlGenerator = $url_generator;
+ $this->currentUser = $current_user;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function create(ContainerInterface $container, array $configuration, $plugin_id, array $plugin_definition) {
+ return new static(
+ $configuration,
+ $plugin_id,
+ $plugin_definition,
+ $container->get('config.factory'),
+ $container->get('url_generator'),
+ $container->get('current_user')
+ );
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function defaultConfiguration() {
+ return array(
+ 'use_site_logo' => TRUE,
+ 'use_site_name' => TRUE,
+ 'use_site_slogan' => TRUE,
+ 'label_display' => FALSE,
+ );
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function blockForm($form, &$form_state) {
+ // Get the theme.
+ $theme = $form_state['block_theme'];
+
+ // Get permissions.
+ $administer_themes_access = $this->currentUser->hasPermission('administer themes');
+ $administer_site_configuration_access = $this->currentUser->hasPermission('administer site configuration');
+
+ if ($administer_themes_access) {
+ // Get paths to theme settings pages.
+ $appearance_url = $this->urlGenerator->generateFromRoute('system.themes_page');
+ $theme_settings_url = $this->urlGenerator->generateFromRoute('system.theme_settings_theme', array('theme' => $theme));
+
+ // Provide links to the Appearance and Theme Settings pages
+ // if the user has access to administer themes.
+ $site_logo_description = $this->t('Defined on the Appearance or Theme Settings page.', array('@appearance' => $appearance_url, '@theme' => $theme_settings_url));
+ }
+ else {
+ // Explain that the user does not have access to the Appearance and Theme
+ // Settings pages.
+ $site_logo_description = $this->t('Defined on the Appearance or Theme Settings page. You do not have the appropriate permissions to change the site logo.');
+ }
+ if ($administer_site_configuration_access) {
+ // Get paths to settings pages.
+ $site_information_url = $this->urlGenerator->generateFromRoute('system.site_information_settings');
+
+ // Provide link to Site Information page if the user has access to
+ // administer site configuration.
+ $site_name_description = $this->t('Defined on the Site Information page.', array('@information' => $site_information_url));
+ $site_slogan_description = $this->t('Defined on the Site Information page.', array('@information' => $site_information_url));
+ }
+ else {
+ // Explain that the user does not have access to the Site Information
+ // page.
+ $site_name_description = $this->t('Defined on the Site Information page. You do not have the appropriate permissions to change the site logo.');
+ $site_slogan_description = $this->t('Defined on the Site Information page. You do not have the appropriate permissions to change the site logo.');
+ }
+
+ $form['block_branding'] = array(
+ '#type' => 'fieldset',
+ '#title' => $this->t('Toggle branding elements'),
+ '#description' => $this->t('Choose which branding elements you want to show in this block instance.'),
+ );
+ $form['block_branding']['use_site_logo'] = array(
+ '#type' => 'checkbox',
+ '#title' => $this->t('Site logo'),
+ '#description' => $site_logo_description,
+ '#default_value' => $this->configuration['use_site_logo'],
+ );
+
+ $form['block_branding']['use_site_name'] = array(
+ '#type' => 'checkbox',
+ '#title' => $this->t('Site name'),
+ '#description' => $site_name_description,
+ '#default_value' => $this->configuration['use_site_name'],
+ );
+ $form['block_branding']['use_site_slogan'] = array(
+ '#type' => 'checkbox',
+ '#title' => $this->t('Site slogan'),
+ '#description' => $site_slogan_description,
+ '#default_value' => $this->configuration['use_site_slogan'],
+ );
+ return $form;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function blockSubmit($form, &$form_state) {
+ $this->configuration['use_site_logo'] = $form_state['values']['block_branding']['use_site_logo'];
+ $this->configuration['use_site_name'] = $form_state['values']['block_branding']['use_site_name'];
+ $this->configuration['use_site_slogan'] = $form_state['values']['block_branding']['use_site_slogan'];
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function build() {
+ $build = array();
+ $site_config = $this->configFactory->get('system.site');
+
+ $logo = theme_get_setting('logo');
+ $build['site_logo'] = array(
+ '#theme' => 'image',
+ '#uri' => $logo['url'],
+ '#alt' => t('Home'),
+ '#access' => $this->configuration['use_site_logo'],
+ );
+
+ $build['site_name'] = array(
+ '#markup' => $site_config->get('name'),
+ '#access' => $this->configuration['use_site_name'],
+ );
+
+ $build['site_slogan'] = array(
+ '#markup' => Xss::filterAdmin($site_config->get('slogan')),
+ '#access' => $this->configuration['use_site_slogan'],
+ );
+
+ return $build;
+ }
+
+}
diff --git a/core/modules/system/system.module b/core/modules/system/system.module
index 34883922b42b16380196c6875fd52e9ac46ff7c5..4befe46025adfaff8e0d6d89e450f7372d9ae46b 100644
--- a/core/modules/system/system.module
+++ b/core/modules/system/system.module
@@ -153,6 +153,14 @@ function system_help($path, $arg) {
*/
function system_theme() {
return array_merge(drupal_common_theme(), array(
+ // Normally theme suggestion templates are only picked up when they are in
+ // themes. We explicitly define the block__system_branding_block theme
+ // suggestion here so that the template in core/modules/system/templates
+ // is picked up.
+ 'block__system_branding_block' => array(
+ 'base hook' => 'block',
+ 'template' => 'block--system-branding-block',
+ ),
'system_themes_page' => array(
'variables' => array(
'theme_groups' => NULL,
@@ -1218,6 +1226,21 @@ function system_user_timezone(&$form, &$form_state) {
*/
function system_preprocess_block(&$variables) {
switch ($variables['base_plugin_id']) {
+ case 'system_branding_block':
+ $variables['site_logo'] = '';
+ if ($variables['content']['site_logo']['#access'] && $variables['content']['site_logo']['#uri']) {
+ $variables['site_logo'] = $variables['content']['site_logo']['#uri'];
+ }
+ $variables['site_name'] = '';
+ if ($variables['content']['site_name']['#access'] && $variables['content']['site_name']['#markup']) {
+ $variables['site_name'] = $variables['content']['site_name']['#markup'];
+ }
+ $variables['site_slogan'] = '';
+ if ($variables['content']['site_slogan']['#access'] && $variables['content']['site_slogan']['#markup']) {
+ $variables['site_slogan'] = $variables['content']['site_slogan']['#markup'];
+ }
+ break;
+
case 'system_powered_by_block':
$variables['attributes']['role'] = 'complementary';
break;
diff --git a/core/modules/system/templates/block--system-branding-block.html.twig b/core/modules/system/templates/block--system-branding-block.html.twig
new file mode 100644
index 0000000000000000000000000000000000000000..2a12c7ae9002dde5c85b9afbe4a7c591b4dffc3b
--- /dev/null
+++ b/core/modules/system/templates/block--system-branding-block.html.twig
@@ -0,0 +1,32 @@
+{% extends "@block/block.html.twig" %}
+{#
+/**
+ * @file
+ * Default theme implementation for a branding block.
+ *
+ * Each branding element variable (logo, name, slogan) is only available if
+ * enabled in the block configuration.
+ *
+ * Available variables:
+ * - site_logo: Logo for site as defined in Appearance or theme settings.
+ * - site_name: Name for site as defined in Site information settings.
+ * - site_slogan: Slogan for site as defined in Site information settings.
+ *
+ * @ingroup themeable
+ */
+#}
+{% block content %}
+ {% if site_logo %}
+
+
+
+ {% endif %}
+ {% if site_name %}
+
+ {% endif %}
+ {% if site_slogan %}
+ {{ site_slogan }}
+ {% endif %}
+{% endblock %}
diff --git a/core/themes/bartik/bartik.theme b/core/themes/bartik/bartik.theme
index b250e3d2c10a8415cf0f7d71c47dc91878f1770c..f90276b3c59a5077c69ede2fdfd58ffe2c9f4bf5 100644
--- a/core/themes/bartik/bartik.theme
+++ b/core/themes/bartik/bartik.theme
@@ -120,6 +120,16 @@ function bartik_preprocess_node(&$variables) {
}
}
+/**
+ * Implements hook_preprocess_HOOK() for block templates.
+ */
+function bartik_preprocess_block(&$variables) {
+ // Add a clearfix class to system branding blocks.
+ if ($variables['plugin_id'] == 'system_branding_block') {
+ $variables['attributes']['class'][] = 'clearfix';
+ }
+}
+
/**
* Implements theme_menu_tree().
*/
diff --git a/core/themes/bartik/css/colors.css b/core/themes/bartik/css/colors.css
index 1ad555a1c1815f43fdff95f81ea84c8f0a8f9045..324215a50079217b3c4ce6b924679bf49a215265 100644
--- a/core/themes/bartik/css/colors.css
+++ b/core/themes/bartik/css/colors.css
@@ -54,7 +54,9 @@ a:active,
.region-header a,
.region-header li a.active,
#name-and-slogan,
+.site-branding-block,
#name-and-slogan a,
+.site-branding-block a,
#secondary-menu-links li a {
color: #fffeff;
}
diff --git a/core/themes/bartik/css/style.css b/core/themes/bartik/css/style.css
index 85c834a66532252f22a96dad36e0b2a0a350ba7f..69a382c0957a4f01bb363acd56b2bed59538ed38 100644
--- a/core/themes/bartik/css/style.css
+++ b/core/themes/bartik/css/style.css
@@ -106,6 +106,7 @@ pre {
body,
#site-slogan,
+.site-slogan,
#page .ui-widget,
.comment-form label,
.node-form label,
@@ -342,35 +343,43 @@ ul.tips {
.skip-link:focus {
outline: 0;
}
-#logo {
+#logo,
+.site-logo {
float: left; /* LTR */
padding-left: 5px; /* LTR */
}
-[dir="rtl"] #logo {
+[dir="rtl"] #logo,
+[dir="rtl"] .site-logo {
padding: 15px 10px 15px 15px;
}
-#name-and-slogan {
+#name-and-slogan,
+.site-branding-text {
float: left; /* LTR */
margin: 0;
padding: 5px 10px 8px;
}
-[dir="rtl"] #name-and-slogan {
+[dir="rtl"] #name-and-slogan,
+[dir="rtl"] .site-branding-text {
margin: 0 15px 30px 0;
}
-#site-name {
+#site-name,
+.site-name {
font-size: 1.6em;
color: #686868;
line-height: 1;
}
-h1#site-name {
+h1#site-name,
+h1.site-name {
margin: 0;
}
-#site-name a {
+#site-name a,
+.site-name a {
font-weight: normal;
}
-#site-slogan {
+#site-slogan,
+.site-slogan {
font-size: 0.929em;
margin-top: 7px;
word-spacing: 0.1em;
@@ -521,7 +530,9 @@ h1#site-name {
}
[dir="rtl"] #logo,
+[dir="rtl"] .site-logo,
[dir="rtl"] #name-and-slogan,
+[dir="rtl"] .site-branding-text,
[dir="rtl"] .region-header .block,
[dir="rtl"] .region-header #block-user-login .form-item,
[dir="rtl"] .region-header #block-user-login .item-list li {
@@ -1757,13 +1768,16 @@ div.admin-panel .description {
.region-header {
margin: .5em 5px .75em;
}
- #logo {
+ #logo,
+ .site-logo {
padding: 5px 0 0 5px; /* LTR */
}
- [dir="rtl"] #logo {
+ [dir="rtl"] #logo,
+ [dir="rtl"] .site-logo {
padding: 5px 5px 0 0;
}
- #name-and-slogan {
+ #name-and-slogan,
+ .site-branding-text {
padding: 10px 10px 8px;
}
#main-menu-links {
@@ -1804,20 +1818,25 @@ div.admin-panel .description {
.region-header {
margin: 1em 5px 1.5em;
}
- #logo {
+ #logo,
+ .site-logo {
padding: 15px 15px 15px 10px; /* LTR */
}
- [dir="rtl"] #logo {
+ [dir="rtl"] #logo,
+ [dir="rtl"] .site-logo {
padding: 15px 10px 15px 15px;
}
- #name-and-slogan {
+ #name-and-slogan,
+ .site-branding-text {
padding: 26px 0 0;
margin: 0 0 30px 15px; /* LTR */
}
- [dir="rtl"] #name-and-slogan {
+ [dir="rtl"] #name-and-slogan,
+ [dir="rtl"] .site-branding-text {
margin: 0 15px 30px 0;
}
- #site-name {
+ #site-name,
+ .site-name {
font-size: 1.821em;
}
#main-menu-links {
diff --git a/core/themes/bartik/templates/block--system-branding-block.html.twig b/core/themes/bartik/templates/block--system-branding-block.html.twig
new file mode 100644
index 0000000000000000000000000000000000000000..c407fe3e3f45258f2f9602ff9fc4d32f37df833c
--- /dev/null
+++ b/core/themes/bartik/templates/block--system-branding-block.html.twig
@@ -0,0 +1,36 @@
+{% extends "@block/block.html.twig" %}
+{#
+/**
+ * @file
+ * Bartik's theme implementation for a branding block.
+ *
+ * Each branding element variable (logo, name, slogan) is only available if
+ * enabled in the block configuration.
+ *
+ * Available variables:
+ * - site_logo: Logo for site as defined in Appearance or theme settings.
+ * - site_name: Name for site as defined in Site information settings.
+ * - site_slogan: Slogan for site as defined in Site information settings.
+ *
+ * @ingroup themeable
+ */
+#}
+{% block content %}
+ {% if site_logo %}
+
+
+
+ {% endif %}
+ {% if site_name or site_slogan %}
+
+ {% if site_name %}
+
+ {{ site_name|e }}
+
+ {% endif %}
+ {% if site_slogan %}
+
{{ site_slogan }}
+ {% endif %}
+
+ {% endif %}
+{% endblock %}