Skip to content

Commit

Permalink
Merge pull request #7 from psu-libraries/6-extend-branding-block-to-a…
Browse files Browse the repository at this point in the history
…dd-ability-to-change-title

Issue #6 - Adding new branding block that user to header-mark sdc fro…
  • Loading branch information
zipymonkey authored Oct 3, 2024
2 parents 12849f3 + df235dc commit 09e8ea1
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 1 deletion.
4 changes: 3 additions & 1 deletion psulib_base_helper.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ name: 'PSULIB Base Theme Helper'
type: module
description: 'Helper module that works with the psulib_base base theme.'
package: PSU Libraries
core_version_requirement: ^10 || ^11
core_version_requirement: ^10 || ^11
dependencies:
- drupal:system
101 changes: 101 additions & 0 deletions src/Plugin/Block/PsulBrandingBlock.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?php

declare(strict_types=1);

namespace Drupal\psulib_base_helper\Plugin\Block;

use Drupal\Core\Form\FormStateInterface;
use Drupal\system\Plugin\Block\SystemBrandingBlock;

/**
* Extend the System Branding Block to add additional controls.
*
* @Block(
* id = "psulib_base_helper_branding_block",
* admin_label = @Translation("PSUL Branding Block"),
* category = @Translation("PSU Libraries"),
* )
*/
final class PsulBrandingBlock extends SystemBrandingBlock {

/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
$defaults = parent::defaultConfiguration();

$defaults['hide_site_name'] = TRUE;
$defaults['use_site_slogan'] = FALSE;
$defaults['logo_title'] = 'Home';
$defaults['logo_path'] = '';

return $defaults;
}

/**
* {@inheritdoc}
*/
public function blockForm($form, FormStateInterface $form_state) {
$form = parent::blockForm($form, $form_state);

$form['block_branding']['hide_site_name'] = [
'#type' => 'checkbox',
'#title' => $this->t('Hide Site name and slogan'),
'#description' => $this->t('Hide the site name and slogan with css.'),
'#default_value' => $this->configuration['hide_site_name'],
];

$form['block_branding']['logo_title'] = [
'#type' => 'textfield',
'#title' => $this->t('Logo title'),
'#description' => $this->t('Set the logo title and alt.'),
'#default_value' => $this->configuration['logo_title'],
];

$form['block_branding']['logo_path'] = [
'#type' => 'url',
'#title' => $this->t('Logo link URL'),
'#description' => $this->t('Update the logo so it links to another site.'),
'#default_value' => $this->configuration['logo_path'],
];

return $form;
}

/**
* {@inheritdoc}
*/
public function blockSubmit($form, FormStateInterface $form_state) {
$block_branding = $form_state->getValue('block_branding');
$this->configuration['use_site_logo'] = $block_branding['use_site_logo'];
$this->configuration['use_site_name'] = $block_branding['use_site_name'];
$this->configuration['use_site_slogan'] = $block_branding['use_site_slogan'];
$this->configuration['hide_site_name'] = $block_branding['hide_site_name'];
$this->configuration['logo_title'] = $block_branding['logo_title'];
$this->configuration['logo_path'] = $block_branding['logo_path'];

}

/**
* {@inheritdoc}
*/
public function build(): array {
$site_config = $this->configFactory->get('system.site');

// Create the header_mark response.
return [
'#type' => 'component',
'#component' => 'psulib_base:header_mark',
'#props' => [
'site_name' => $this->configuration['use_site_name'] ? $site_config->get('name') : '',
'site_logo' => $this->configuration['use_site_logo'] ? theme_get_setting('logo.url') : '',
'site_slogan' => $this->configuration['use_site_slogan'] ? $site_config->get('slogan') : '',
'hide_site_name' => $this->configuration['hide_site_name'],
'logo_title' => $this->configuration['logo_title'],
'logo_path' => $this->configuration['logo_path'],
],
];

}

}

0 comments on commit 09e8ea1

Please sign in to comment.