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..fa04d9e --- /dev/null +++ b/core/modules/system/lib/Drupal/system/Plugin/Block/SystemBrandingBlock.php @@ -0,0 +1,135 @@ +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( + 'site_logo' => TRUE, + 'site_name' => TRUE, + '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' => t('Choose which branding elements you want to show in this block instance.'), + '#collapsed' => FALSE, + '#collapsible' => FALSE, + ); + $form['block_branding']['site_logo'] = array( + '#type' => 'checkbox', + '#title' => $this->t('Site logo'), + '#default_value' => $this->configuration['site_logo'], + ); + $form['block_branding']['site_name'] = array( + '#type' => 'checkbox', + '#title' => $this->t('Site name'), + '#default_value' => $this->configuration['site_name'], + ); + $form['block_branding']['site_slogan'] = array( + '#type' => 'checkbox', + '#title' => $this->t('Site slogan'), + '#default_value' => $this->configuration['site_slogan'], + ); + return $form; + } + + /** + * {@inheritdoc} + */ + public function blockSubmit($form, &$form_state) { + $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']; + } + + /** + * {@inheritdoc} + */ + public function build() { + $build = array(); + $site_config = $this->configFactory->get('system.site'); + $build['#theme'] = 'branding'; + + // Logo + $build['#use_site_logo'] = $this->configuration['site_logo']; + $build['#site_logo'] = theme_get_setting('logo'); + + // Site name + $build['#use_site_name'] = $this->configuration['site_name']; + $build['#site_name'] = $site_config->get('name'); + + // Site slogan + $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..f134aab --- /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 %}