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 0000000..99988bb --- /dev/null +++ b/core/modules/block/lib/Drupal/block/Tests/BlockSystemBrandingTest.php @@ -0,0 +1,116 @@ + 'System Branding Block', + 'description' => 'Tests branding block display.', + 'group' => 'Block', + ); + } + + 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. + */ + function testSystemBrandingSettings() { + // Set default block settings and test that all branding elements are displayed. + $this->drupalGet(''); + $site_logo_element = $this->xpath('//div[@id="block-site-branding"]//a[@class="site-logo"]'); + $site_name_slogan_element = $this->xpath('//div[@id="block-site-branding"]//div[@class="name-and-slogan"]'); + $site_name_element = $this->xpath('//div[@id="block-site-branding"]//strong[@class="site-name"]'); + $site_slogan_element = $this->xpath('//div[@id="block-site-branding"]//div[@class="site-slogan"]'); + $this->assertTrue(!empty($site_logo_element), 'The branding block logo was found.'); + $this->assertTrue(!empty($site_name_slogan_element), 'The branding block name and slogan div 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, and re-test all branding elements. + \Drupal::config('block.block.site-branding') + ->set('settings.use_site_logo', 0) + ->save(); + $this->drupalGet(''); + $site_logo_element = $this->xpath('//div[@id="block-site-branding"]//a[@class="site-logo"]'); + $site_name_slogan_element = $this->xpath('//div[@id="block-site-branding"]//div[@class="name-and-slogan"]'); + $site_name_element = $this->xpath('//div[@id="block-site-branding"]//strong[@class="site-name"]'); + $site_slogan_element = $this->xpath('//div[@id="block-site-branding"]//div[@class="site-slogan"]'); + $this->assertTrue(empty($site_logo_element), 'The branding block logo was disabled.'); + $this->assertTrue(!empty($site_name_slogan_element), 'The branding block name and slogan div 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 site name off, and re-test all branding elements. + \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('//div[@id="block-site-branding"]//a[@class="site-logo"]'); + $site_name_slogan_element = $this->xpath('//div[@id="block-site-branding"]//div[@class="name-and-slogan"]'); + $site_name_element = $this->xpath('//div[@id="block-site-branding"]//strong[@class="site-name"]'); + $site_slogan_element = $this->xpath('//div[@id="block-site-branding"]//div[@class="site-slogan"]'); + $this->assertTrue(!empty($site_logo_element), 'The branding block logo was found.'); + $this->assertTrue(!empty($site_name_slogan_element), 'The branding block name and slogan div 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, and re-test all branding elements. + \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('//div[@id="block-site-branding"]//a[@class="site-logo"]'); + $site_name_slogan_element = $this->xpath('//div[@id="block-site-branding"]//div[@class="name-and-slogan"]'); + $site_name_element = $this->xpath('//div[@id="block-site-branding"]//strong[@class="site-name"]'); + $site_slogan_element = $this->xpath('//div[@id="block-site-branding"]//div[@class="site-slogan"]'); + $this->assertTrue(!empty($site_logo_element), 'The branding block logo was found.'); + $this->assertTrue(!empty($site_name_slogan_element), 'The branding block name and slogan div 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, and re-test all branding elements. + \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('//div[@id="block-site-branding"]//a[@class="site-logo"]'); + $site_name_slogan_element = $this->xpath('//div[@id="block-site-branding"]//div[@class="name-and-slogan"]'); + $site_name_element = $this->xpath('//div[@id="block-site-branding"]//strong[@class="site-name"]'); + $site_slogan_element = $this->xpath('//div[@id="block-site-branding"]//div[@class="site-slogan"]'); + $this->assertTrue(!empty($site_logo_element), 'The branding block logo was found.'); + $this->assertTrue(empty($site_name_slogan_element), 'The branding block name and slogan div 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.'); + + } + +} 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 0000000..6336809 --- /dev/null +++ b/core/modules/system/lib/Drupal/system/Plugin/Block/SystemBrandingBlock.php @@ -0,0 +1,132 @@ +configFactory = $config_factory; + } + + /** + * {@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') + ); + } + + /** + * {@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) { + $form['block_branding'] = array( + '#type' => 'details', + '#title' => $this->t('Toggle branding elements'), + '#description' => $this->t('Choose which branding elements you want to show in this block instance.'), + '#collapsed' => FALSE, + '#collapsible' => FALSE, + ); + $form['block_branding']['use_site_logo'] = array( + '#type' => 'checkbox', + '#title' => $this->t('Site logo'), + '#default_value' => $this->configuration['use_site_logo'], + ); + $form['block_branding']['use_site_name'] = array( + '#type' => 'checkbox', + '#title' => $this->t('Site name'), + '#default_value' => $this->configuration['use_site_name'], + ); + $form['block_branding']['use_site_slogan'] = array( + '#type' => 'checkbox', + '#title' => $this->t('Site slogan'), + '#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'); + $build['#theme'] = 'branding'; + + $build['#use_site_logo'] = $this->configuration['use_site_logo']; + $build['#site_logo'] = theme_get_setting('logo'); + + $build['#use_site_name'] = $this->configuration['use_site_name']; + $build['#site_name'] = $site_config->get('name'); + + $build['#use_site_slogan'] = $this->configuration['use_site_slogan']; + $build['#site_slogan'] = Xss::filterAdmin($site_config->get('slogan')); + + return $build; + } + +} diff --git a/core/modules/system/system.module b/core/modules/system/system.module index 1f8ee83..032cb44 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -152,6 +152,17 @@ function system_help($path, $arg) { */ function system_theme() { return array_merge(drupal_common_theme(), array( + 'branding' => array( + 'variables' => array( + 'use_site_logo' => FALSE, + 'site_logo' => array(), + 'use_site_name' => FALSE, + 'site_name' => '', + 'use_site_slogan' => FALSE, + 'site_slogan' => '', + ), + 'template' => 'branding', + ), 'system_themes_page' => array( 'variables' => array( 'theme_groups' => NULL, diff --git a/core/modules/system/templates/branding.html.twig b/core/modules/system/templates/branding.html.twig new file mode 100644 index 0000000..bfcbc08 --- /dev/null +++ b/core/modules/system/templates/branding.html.twig @@ -0,0 +1,40 @@ +{# +/** + * @file + * Default theme implementation for a branding block. + * + * Available variables: + * - use_site_logo: Block setting on whether to show the site logo. + * - use_site_name: Block setting on whether to show the site name. + * - use_site_slogan: Block setting on whether to show the site slogan. + * + * - site_logo: Logo for site. + * - site_name: Name for site. + * - site_slogan: Slogan for site. + * + * @ingroup themeable + */ +#} +{% if use_site_logo and site_logo %} + +{% endif %} + +{% if use_site_name or (use_site_slogan and site_slogan) %} + +
+ + {% if use_site_name %} + + {{ site_name|e|t }} + + {% endif %} + + {% if use_site_slogan and site_slogan %} +
{{ site_slogan|t }}
+ {% endif %} + +
+ +{% endif %}