diff --git a/core/modules/block/lib/Drupal/block/BlockFormController.php b/core/modules/block/lib/Drupal/block/BlockFormController.php index 3419afc..2d74a70 100644 --- a/core/modules/block/lib/Drupal/block/BlockFormController.php +++ b/core/modules/block/lib/Drupal/block/BlockFormController.php @@ -93,6 +93,16 @@ public static function create(ContainerInterface $container) { */ public function form(array $form, array &$form_state) { $entity = $this->entity; + + // Store theme settings in $form_state and use them in the theme settings below. + if ($entity->get('theme')) { + $theme = $entity->get('theme'); + } + else { + $theme = $this->configFactory->get('system.theme')->get('default'); + } + $form_state['block_theme'] = $theme; + $form['#tree'] = TRUE; $form['settings'] = $entity->getPlugin()->buildConfigurationForm(array(), $form_state); @@ -232,7 +242,7 @@ public function form(array $form, array &$form_state) { if ($theme = $entity->get('theme')) { $form['theme'] = array( '#type' => 'value', - '#value' => $entity->get('theme'), + '#value' => $theme, ); } else { @@ -242,7 +252,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, @@ -254,6 +263,8 @@ public function form(array $form, array &$form_state) { ), ); } + $form_state['block_theme'] = $theme; + // Region settings. $form['region'] = array( '#type' => 'select', diff --git a/core/modules/block/lib/Drupal/block/Tests/BlockSystemBrandingTest.php b/core/modules/block/lib/Drupal/block/Tests/BlockSystemBrandingTest.php index 4d8ca07..38f78b9 100644 --- a/core/modules/block/lib/Drupal/block/Tests/BlockSystemBrandingTest.php +++ b/core/modules/block/lib/Drupal/block/Tests/BlockSystemBrandingTest.php @@ -42,7 +42,7 @@ function setUp() { */ function testSystemBrandingSettings() { $site_logo_xpath = '//div[@id="block-site-branding"]//a[@class="site-logo"]'; - $site_name_xpath = '//div[@id="block-site-branding"]//strong[@class="site-name"]'; + $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. diff --git a/core/modules/system/lib/Drupal/system/Plugin/Block/SystemBrandingBlock.php b/core/modules/system/lib/Drupal/system/Plugin/Block/SystemBrandingBlock.php index bcbf028..9753ab0 100644 --- a/core/modules/system/lib/Drupal/system/Plugin/Block/SystemBrandingBlock.php +++ b/core/modules/system/lib/Drupal/system/Plugin/Block/SystemBrandingBlock.php @@ -10,8 +10,10 @@ use Drupal\block\BlockBase; use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; +use Drupal\Core\Routing\UrlGeneratorInterface; use Drupal\Component\Utility\Xss; use Symfony\Component\DependencyInjection\ContainerInterface; +use Symfony\Component\HttpFoundation\Request; /** * Provides a block to display 'Site branding' elements. @@ -24,6 +26,13 @@ class SystemBrandingBlock extends BlockBase implements ContainerFactoryPluginInterface { /** + * The URL generator. + * + * @var \Drupal\Core\Routing\UrlGeneratorInterface + */ + protected $urlGenerator; + + /** * Stores the configuration factory. * * @var \Drupal\Core\Config\ConfigFactoryInterface @@ -31,6 +40,13 @@ class SystemBrandingBlock extends BlockBase implements ContainerFactoryPluginInt protected $configFactory; /** + * The current request. + * + * @var \Symfony\Component\HttpFoundation\Request + */ + protected $request; + + /** * Creates a SystemBrandingBlock instance. * * @param array $configuration @@ -41,10 +57,16 @@ class SystemBrandingBlock extends BlockBase implements ContainerFactoryPluginInt * The plugin implementation definition. * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory * The factory for configuration objects. + * @param \Drupal\Core\Routing\UrlGeneratorInterface $url_generator + * The url generator service. + * @param \Symfony\Component\HttpFoundation\Request + * The current request. */ - public function __construct(array $configuration, $plugin_id, array $plugin_definition, ConfigFactoryInterface $config_factory) { + public function __construct(array $configuration, $plugin_id, array $plugin_definition, ConfigFactoryInterface $config_factory, UrlGeneratorInterface $url_generator, Request $request) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->configFactory = $config_factory; + $this->urlGenerator = $url_generator; + $this->request = $request; } /** @@ -55,11 +77,26 @@ public static function create(ContainerInterface $container, array $configuratio $configuration, $plugin_id, $plugin_definition, - $container->get('config.factory') + $container->get('config.factory'), + $container->get('url_generator'), + $container->get('request') ); } /** + * Generates a URL or path for a specific route based on the given parameters. + * + * @see \Drupal\Core\Routing\UrlGeneratorInterface::generateFromRoute() for + * details on the arguments, usage, and possible exceptions. + * + * @return string + * The generated URL for the given route. + */ + public function url($route_name, $route_parameters = array(), $options = array()) { + return $this->urlGenerator->generateFromRoute($route_name, $route_parameters, $options); + } + + /** * {@inheritdoc} */ public function defaultConfiguration() { @@ -75,6 +112,43 @@ public function defaultConfiguration() { * {@inheritdoc} */ public function blockForm($form, &$form_state) { + // Get the theme. + if ($this->request->attributes->get('theme')) { + // Get the theme from request if available. + $theme = $this->request->attributes->get('theme'); + } + else { + $theme = $form_state['block_theme']; + } + + // Get permissions. + $administer_themes_access = \Drupal::currentUser()->hasPermission('administer themes'); + $administer_site_configuration_access = \Drupal::currentUser()->hasPermission('administer site configuration'); + + if ($administer_themes_access) { + // Get paths to theme settings pages. + $appearance_url = $this->url('system.themes_page'); + $theme_settings_url = $this->url('system.theme_settings_theme', array('theme' => $theme)); + + // Provide links to the Appearance and Theme Settings pages if 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 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->url('system.site_information_settings'); + + // Provide link to Site Information page if 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 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' => 'details', '#title' => $this->t('Toggle branding elements'), @@ -85,19 +159,20 @@ public function blockForm($form, &$form_state) { $form['block_branding']['use_site_logo'] = array( '#type' => 'checkbox', '#title' => $this->t('Site logo'), - '#description' => $this->t('Defined in Appearance or theme settings.'), + '#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' => $this->t('Defined in Site information settings.'), + '#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' => $this->t('Defined in Site information settings.'), + '#description' => $site_slogan_description, '#default_value' => $this->configuration['use_site_slogan'], ); return $form; diff --git a/core/modules/system/templates/branding.html.twig b/core/modules/system/templates/branding.html.twig index 4b760be..36aa4f2 100644 --- a/core/modules/system/templates/branding.html.twig +++ b/core/modules/system/templates/branding.html.twig @@ -19,16 +19,11 @@ {{ 'Home'|t }} {% endif %} - -{% if use_site_name or (use_site_slogan and site_slogan) %} -
- {% if use_site_name %} - - {{ site_name|e }} - - {% endif %} - {% if use_site_slogan and site_slogan %} -
{{ site_slogan }}
- {% endif %} +{% if use_site_name %} +
+ {{ site_name|e }}
{% endif %} +{% if use_site_slogan and site_slogan %} +
{{ site_slogan }}
+{% endif %} diff --git a/core/themes/bartik/css/colors.css b/core/themes/bartik/css/colors.css index 1ad555a..324215a 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 85c834a..69a382c 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/branding.html.twig b/core/themes/bartik/templates/branding.html.twig new file mode 100644 index 0000000..f1cb935 --- /dev/null +++ b/core/themes/bartik/templates/branding.html.twig @@ -0,0 +1,34 @@ +{# +/** + * @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 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 + */ +#} +{% 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 }} + + {% endif %} + {% if use_site_slogan and site_slogan %} +
{{ site_slogan }}
+ {% endif %} +
+{% endif %}