Skip to content

Commit 963d46f

Browse files
authored
Merge pull request #40 from psu-libraries/39-fix-linter-issue-in-block
39 fix linter issue in block
2 parents 3bd519e + 18f01db commit 963d46f

File tree

4 files changed

+40
-28
lines changed

4 files changed

+40
-28
lines changed

psulib_base_helper.install

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
/**
4+
* @file
5+
* Install, update and uninstall functions for the psulib_base_helper module.
6+
*/
7+
8+
/**
9+
* Remove unsupported configs from psulib_base settings.
10+
*/
11+
function psulib_base_helper_update_10001() {
12+
$config = \Drupal::configFactory()->getEditable('psulib_base.settings');
13+
$schema = \Drupal::service('config.typed')->getDefinition('psulib_base.settings');
14+
15+
if ($schema) {
16+
$supported_keys = array_keys($schema['mapping'] ?? []);
17+
$current_data = $config->getRawData();
18+
19+
foreach (array_keys($current_data) as $key) {
20+
if ($key !== 'uuid' && $key !== '_core' && !in_array($key, $supported_keys)) {
21+
$config->clear($key);
22+
}
23+
}
24+
25+
$config->save();
26+
}
27+
}

src/Hook/ThemeHooks.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace Drupal\psulib_base_helper\Hook;
66

7-
use Drupal\Core\Config\ConfigFactoryInterface;
7+
use Drupal\Core\Extension\ThemeSettingsProvider;
88
use Drupal\Core\Hook\Attribute\Hook;
99
use Drupal\psulib_base_helper\PsuFederatedDataFetcher;
1010

@@ -18,7 +18,7 @@ class ThemeHooks {
1818
*/
1919
public function __construct(
2020
private readonly PsuFederatedDataFetcher $dataFetcher,
21-
private readonly ConfigFactoryInterface $configFactory,
21+
private readonly ThemeSettingsProvider $themeSettingsProvider,
2222
) {}
2323

2424
/**
@@ -28,9 +28,7 @@ public function __construct(
2828
*/
2929
#[Hook('preprocess_page')]
3030
public function preprocessPage(&$variables): void {
31-
$show_federated_footer = $this->configFactory
32-
->get('psulib_base.settings')
33-
->get('show_federated_footer');
31+
$show_federated_footer = $this->themeSettingsProvider->getSetting('show_federated_footer');
3432

3533
if (!$show_federated_footer) {
3634
return;

src/Plugin/Block/PsulBrandingBlock.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* category = @Translation("PSU Libraries"),
1717
* )
1818
*/
19-
final class PsulBrandingBlock extends SystemBrandingBlock {
19+
class PsulBrandingBlock extends SystemBrandingBlock {
2020

2121
/**
2222
* {@inheritdoc}
@@ -88,7 +88,7 @@ public function build(): array {
8888
'#component' => 'psulib_base:header_mark',
8989
'#props' => [
9090
'site_name' => $this->configuration['use_site_name'] ? $site_config->get('name') : '',
91-
'site_logo' => $this->configuration['use_site_logo'] ? \Drupal::service('Drupal\Core\Extension\ThemeSettingsProvider')->getSetting('logo.url') : '',
91+
'site_logo' => $this->configuration['use_site_logo'] ? $this->themeSettingsProvider->getSetting('logo.url') : '',
9292
'site_slogan' => $this->configuration['use_site_slogan'] ? $site_config->get('slogan') : '',
9393
'hide_site_name' => (bool) $this->configuration['hide_site_name'],
9494
'logo_title' => $this->configuration['logo_title'],

tests/src/Unit/Hook/ThemeHooksTest.php

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44

55
namespace Drupal\Tests\psulib_base_helper\Unit\Hook;
66

7-
use Drupal\Core\Config\ConfigFactoryInterface;
8-
use Drupal\Core\Config\ImmutableConfig;
7+
use Drupal\Core\Extension\ThemeSettingsProvider;
98
use Drupal\psulib_base_helper\Hook\ThemeHooks;
109
use Drupal\psulib_base_helper\PsuFederatedDataFetcher;
1110
use Drupal\Tests\UnitTestCase;
@@ -29,18 +28,11 @@ class ThemeHooksTest extends UnitTestCase {
2928
protected $dataFetcher;
3029

3130
/**
32-
* The mocked config factory.
31+
* The mocked theme settings provider.
3332
*
34-
* @var \Drupal\Core\Config\ConfigFactoryInterface|\PHPUnit\Framework\MockObject\MockObject
33+
* @var \Drupal\Core\Extension\ThemeSettingsProvider|\PHPUnit\Framework\MockObject\MockObject
3534
*/
36-
protected $configFactory;
37-
38-
/**
39-
* The mocked config.
40-
*
41-
* @var \Drupal\Core\Config\ImmutableConfig|\PHPUnit\Framework\MockObject\MockObject
42-
*/
43-
protected $config;
35+
protected $themeSettingsProvider;
4436

4537
/**
4638
* The ThemeHooks instance.
@@ -56,16 +48,11 @@ protected function setUp(): void {
5648
parent::setUp();
5749

5850
$this->dataFetcher = $this->createMock(PsuFederatedDataFetcher::class);
59-
$this->configFactory = $this->createMock(ConfigFactoryInterface::class);
60-
$this->config = $this->createMock(ImmutableConfig::class);
61-
62-
$this->configFactory->method('get')
63-
->with('psulib_base.settings')
64-
->willReturn($this->config);
51+
$this->themeSettingsProvider = $this->createMock(ThemeSettingsProvider::class);
6552

6653
$this->hooks = new ThemeHooks(
6754
$this->dataFetcher,
68-
$this->configFactory
55+
$this->themeSettingsProvider
6956
);
7057
}
7158

@@ -74,7 +61,7 @@ protected function setUp(): void {
7461
*/
7562
#[Test]
7663
public function testFederatedFooterAddedWhenSettingsAndDataPresent(): void {
77-
$this->config->method('get')
64+
$this->themeSettingsProvider->method('getSetting')
7865
->with('show_federated_footer')
7966
->willReturn(TRUE);
8067

@@ -118,7 +105,7 @@ public function testFederatedFooterAddedWhenSettingsAndDataPresent(): void {
118105
#[Test]
119106
#[DataProvider('federatedFooterNotAddedProvider')]
120107
public function testFederatedFooterNotAddedWhenNoDataOrDisabled(?bool $showSetting, array $data, bool $expectFetcherCall): void {
121-
$this->config->method('get')
108+
$this->themeSettingsProvider->method('getSetting')
122109
->with('show_federated_footer')
123110
->willReturn($showSetting);
124111

0 commit comments

Comments
 (0)