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 b4977b8..6a6f930 100644 --- a/core/modules/system/lib/Drupal/system/Plugin/Block/SystemBrandingBlock.php +++ b/core/modules/system/lib/Drupal/system/Plugin/Block/SystemBrandingBlock.php @@ -10,26 +10,65 @@ use Drupal\block\BlockBase; use Drupal\block\Annotation\Block; use Drupal\Core\Annotation\Translation; -use Drupal\Component\Utility\String; +use Drupal\Core\Config\ConfigFactory; +use Drupal\Core\Plugin\ContainerFactoryPluginInterface; +use Drupal\Component\Utility\Xss; +use Symfony\Component\DependencyInjection\ContainerInterface; /** - * Provides a block to display 'Site Branding' elements. + * Provides a block to display 'Site branding' elements. * * @Block( * id = "system_branding_block", - * admin_label = @Translation("Site Branding") + * admin_label = @Translation("Site branding") * ) */ -class SystemBrandingBlock extends BlockBase { +class SystemBrandingBlock extends BlockBase implements ContainerFactoryPluginInterface { + + /** + * Stores the configuration factory. + * + * @var \Drupal\Core\Config\ConfigFactory + */ + protected $configFactory; + + /** + * Creates a SystemBrandingBlock instance. + * + * @param array $configuration + * A configuration array containing information about the plugin instance. + * @param string $plugin_id + * The plugin_id for the plugin instance. + * @param array $plugin_definition + * The plugin implementation definition. + * @param \Drupal\Core\Config\ConfigFactory $configFactory + * The factory for configuration objects. + */ + public function __construct(array $configuration, $plugin_id, array $plugin_definition, ConfigFactory $configFactory) { + parent::__construct($configuration, $plugin_id, $plugin_definition); + $this->configFactory = $configFactory; + } + + /** + * {@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( - 'logo' => TRUE, - 'sitename' => TRUE, - 'siteslogan' => TRUE, + 'site_logo' => TRUE, + 'site_name' => TRUE, + 'site_slogan' => TRUE, ); } @@ -39,25 +78,25 @@ public function defaultConfiguration() { public function blockForm($form, &$form_state) { $form['block_branding'] = array( '#type' => 'details', - '#title' => t('Toggle branding elements'), + '#title' => $this->t('Toggle branding elements'), '#description' => t('Choose which branding elements you want to show in this block instance.'), '#collapsed' => FALSE, '#collapsible' => FALSE, ); - $form['block_branding']['logo'] = array( + $form['block_branding']['site_logo'] = array( '#type' => 'checkbox', - '#title' => t('Logo'), - '#default_value' => $this->configuration['logo'], + '#title' => $this->t('Site logo'), + '#default_value' => $this->configuration['site_logo'], ); - $form['block_branding']['sitename'] = array( + $form['block_branding']['site_name'] = array( '#type' => 'checkbox', - '#title' => t('Site name'), - '#default_value' => $this->configuration['sitename'], + '#title' => $this->t('Site name'), + '#default_value' => $this->configuration['site_name'], ); - $form['block_branding']['siteslogan'] = array( + $form['block_branding']['site_slogan'] = array( '#type' => 'checkbox', - '#title' => t('Site slogan'), - '#default_value' => $this->configuration['siteslogan'], + '#title' => $this->t('Site slogan'), + '#default_value' => $this->configuration['site_slogan'], ); return $form; } @@ -66,9 +105,9 @@ public function blockForm($form, &$form_state) { * Overrides \Drupal\block\BlockBase::blockSubmit(). */ public function blockSubmit($form, &$form_state) { - $this->configuration['logo'] = $form_state['values']['block_branding']['logo']; - $this->configuration['sitename'] = $form_state['values']['block_branding']['sitename']; - $this->configuration['siteslogan'] = $form_state['values']['block_branding']['siteslogan']; + $this->configuration['site_logo'] = $form_state['values']['block_branding']['site_logo']; + $this->configuration['site_name'] = $form_state['values']['block_branding']['site_name']; + $this->configuration['site_slogan'] = $form_state['values']['block_branding']['site_slogan']; } /** @@ -76,40 +115,22 @@ public function blockSubmit($form, &$form_state) { */ public function build() { $build = array(); - $site_config = \Drupal::config('system.site'); + $site_config = $this->configFactory->get('system.site'); + $build['#theme'] = 'branding'; + // Logo - if ($this->configuration['logo'] == TRUE) { - $logo = theme_get_setting('logo'); - if (!empty($logo)) { - $image = '' . t('Home') . ''; - $build['branding']['logo'] = array( - '#markup' => l($image, '', array('html' => TRUE, 'attributes' => array('rel' => 'home', 'class' => array('logo'), 'title' => t('Home')))), - '#weight' => 0, - ); - } - } + $build['#use_site_logo'] = $this->configuration['site_logo']; + $build['#site_logo'] = theme_get_setting('logo'); + // Site name - if ($this->configuration['sitename'] == TRUE) { - $sitename = String::checkPlain($site_config->get('name')); - $build['branding']['sitename'] = array( - '#markup' => l($sitename, '', array('attributes' => array('rel' => 'home', 'title' => t('Home')))), - '#prefix' => '

', - '#suffix' => '

', - '#weight' => 1, - ); - } + $build['#use_site_name'] = $this->configuration['site_name']; + $build['#site_name'] = $site_config->get('name'); + // Site slogan - if ($this->configuration['siteslogan'] == TRUE) { - $slogan = filter_xss_admin($site_config->get('slogan')); - if (!empty($slogan)) { - $build['branding']['siteslogan'] = array( - '#markup' => $slogan, - '#prefix' => '

', - '#suffix' => '

', - '#weight' => 2, - ); - } - } + $build['#use_site_slogan'] = $this->configuration['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 1657f9f..670bd2f 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..d72276b --- /dev/null +++ b/core/modules/system/templates/branding.html.twig @@ -0,0 +1,22 @@ +{# +/** + * @file + * Default theme implementation for a branding block. + * + * Available variables: + * - site_logo: Logo for site. + * - site_name: Name for site. + * - site_slogan: Slogan for site. + * + * @ingroup themeable + */ +#} +{% if use_site_logo %} + +{% endif %} +{% if use_site_name %} +

{{ site_name|e|t }}

+{% endif %} +{% if use_site_slogan %} +

{{ site_slogan|t }}

+{% endif %}