Skip to content

Commit 2a60eda

Browse files
committed
feat(phpcs): Correct any issues reported by phpcs
1 parent 04c2498 commit 2a60eda

12 files changed

+66
-17
lines changed

src/Controller/LibraryController.php

+5
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,14 @@
66
use Drupal\Core\Controller\ControllerBase;
77
use Symfony\Component\DependencyInjection\ContainerInterface;
88

9+
/**
10+
* Provides a library controller.
11+
*/
912
class LibraryController extends ControllerBase {
1013

1114
/**
15+
* The library service.
16+
*
1217
* @var \Drupal\wxt_library\LibraryService
1318
*/
1419
protected $wxtLibraryService;

src/Form/SearchApiBlockForm.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
127127
}
128128

129129
/**
130-
* Custom after build to remove elements from being submitted as GET variables.
130+
* Remove elements from being submitted as GET variables.
131131
*/
132132
public function afterBuild(array $element, FormStateInterface $form_state) {
133133
// Remove the form_build_id, form_id and op from the GET parameters.

src/Form/SearchBlockForm.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
111111
$form['keys'] = [
112112
'#id' => 'wb-srch-q',
113113
'#type' => 'search',
114-
'#title' => t('Search'),
114+
'#title' => $this->t('Search'),
115115
'#title_display' => 'invisible',
116116
'#size' => 27,
117117
'#maxlength' => 128,

src/Form/SearchCanadaBlockForm.php

+14-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Drupal\Core\Form\FormBase;
77
use Drupal\Core\Form\FormStateInterface;
88
use Drupal\Core\Render\RendererInterface;
9+
use Drupal\Core\Language\LanguageManagerInterface;
910
use Drupal\wxt_library\LibraryService;
1011
use Symfony\Component\DependencyInjection\ContainerInterface;
1112

@@ -21,6 +22,13 @@ class SearchCanadaBlockForm extends FormBase {
2122
*/
2223
protected $configFactory;
2324

25+
/**
26+
* Language manager for retrieving the default langcode.
27+
*
28+
* @var \Drupal\Core\Language\LanguageManagerInterface
29+
*/
30+
protected $languageManager;
31+
2432
/**
2533
* The renderer.
2634
*
@@ -40,17 +48,21 @@ class SearchCanadaBlockForm extends FormBase {
4048
*
4149
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
4250
* The config factory.
51+
* @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
52+
* The language manager.
4353
* @param \Drupal\Core\Render\RendererInterface $renderer
4454
* The renderer.
4555
* @param \Drupal\wxt_library\LibraryService $wxt_library_service_wxt
4656
* The LibraryService.
4757
*/
4858
public function __construct(
4959
ConfigFactoryInterface $config_factory,
60+
LanguageManagerInterface $language_manager,
5061
RendererInterface $renderer,
5162
LibraryService $wxt_library_service_wxt
5263
) {
5364
$this->configFactory = $config_factory;
65+
$this->languageManager = $language_manager;
5466
$this->renderer = $renderer;
5567
$this->wxtLibraryServiceWxT = $wxt_library_service_wxt;
5668
}
@@ -83,7 +95,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
8395
$form['keys'] = [
8496
'#id' => 'wb-srch-q',
8597
'#type' => 'search',
86-
'#title' => t('Search'),
98+
'#title' => $this->t('Search'),
8799
'#title_display' => 'invisible',
88100
'#size' => 27,
89101
'#maxlength' => 128,
@@ -112,7 +124,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
112124
$form['submit_container']['submit']['#value'] = '';
113125
$form['keys']['#placeholder'] = $this->t('Search website');
114126

115-
$lang = \Drupal::languageManager()->getCurrentLanguage()->getId();
127+
$lang = $this->languageManager->getCurrentLanguage()->getId();
116128

117129
$form['#action'] = 'https://www.canada.ca/' . $lang . '/sr/srb.html#wb_land';
118130
$form['#method'] = 'get';

src/LibraryService.php

+7
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,21 @@
55
use Drupal\Core\Config\ConfigFactoryInterface;
66
use Symfony\Component\DependencyInjection\ContainerInterface;
77

8+
/**
9+
* Provides a library service for WxT.
10+
*/
811
class LibraryService {
912

1013
/**
14+
* Consructs the library name.
15+
*
1116
* @var string
1217
*/
1318
protected $libraryName;
1419

1520
/**
21+
* Consructs the library path.
22+
*
1623
* @var string
1724
*/
1825
protected $libraryPath;

src/Plugin/Block/DateModifiedBlock.php

+13-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use Drupal\Component\Datetime\TimeInterface;
66
use Drupal\Core\Block\BlockBase;
77
use Drupal\Core\Datetime\DateFormatter;
8-
use Drupal\Core\Datetime\Entity\DateFormat;
98
use Drupal\Core\Entity\EntityStorageInterface;
109
use Drupal\Core\Form\FormStateInterface;
1110
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
@@ -30,6 +29,13 @@ class DateModifiedBlock extends BlockBase implements ContainerFactoryPluginInter
3029
*/
3130
protected $requestStack;
3231

32+
/**
33+
* The date format storage.
34+
*
35+
* @var \Drupal\Core\Entity\EntityStorageInterface
36+
*/
37+
protected $dateFormatStorage;
38+
3339
/**
3440
* The node storage.
3541
*
@@ -60,6 +66,8 @@ class DateModifiedBlock extends BlockBase implements ContainerFactoryPluginInter
6066
* The plugin_id for the plugin instance.
6167
* @param string $plugin_definition
6268
* The plugin implementation definition.
69+
* @param \Drupal\Core\Entity\EntityStorageInterface $date_format_storage
70+
* Entity storage for date_format entities.
6371
* @param \Drupal\Core\Datetime\DateFormatter $date_formatter
6472
* The date formatter service.
6573
* @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
@@ -73,12 +81,14 @@ public function __construct(
7381
array $configuration,
7482
$plugin_id,
7583
$plugin_definition,
84+
EntityStorageInterface $date_format_storage,
7685
DateFormatter $date_formatter,
7786
RequestStack $request_stack,
7887
EntityStorageInterface $node_storage,
7988
TimeInterface $date_time
8089
) {
8190
parent::__construct($configuration, $plugin_id, $plugin_definition);
91+
$this->dateFormatStorage = $date_format_storage;
8292
$this->dateFormatter = $date_formatter;
8393
$this->requestStack = $request_stack;
8494
$this->nodeStorage = $node_storage;
@@ -93,6 +103,7 @@ public static function create(ContainerInterface $container, array $configuratio
93103
$configuration,
94104
$plugin_id,
95105
$plugin_definition,
106+
$container->get('entity_type.manager')->getStorage('date_format'),
96107
$container->get('date.formatter'),
97108
$container->get('request_stack'),
98109
$container->get('entity_type.manager')->getStorage('node'),
@@ -162,7 +173,7 @@ public function build() {
162173
$formatted_date = 'Y-m-d';
163174
}
164175
else {
165-
$formatted_date = DateFormat::load($format)->getPattern();
176+
$formatted_date = $this->dateFormatStorage->load($format)->getPattern();
166177
}
167178
$date = $this->dateFormatter->format($time, 'custom', $formatted_date);
168179

src/Plugin/Block/LanguageBlock.php

-2
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,6 @@ public function build() {
124124
$current = $this->urlGenerator->generateFromRoute('<current>', [], [], TRUE)->getGeneratedUrl();
125125
$front = $this->aliasManager->getPathByAlias($current);
126126
$frontAlias = $this->configFactory->get('system.site')->get('page.front');
127-
128-
$config = $this->configuration;
129127
$build = [];
130128
$route_name = $this->pathMatcher->isFrontPage() ? '<front>' : '<current>';
131129

src/Plugin/Block/UserAccountBlock.php

+9-3
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,19 @@ public function build() {
7373
$build['user_account_block']['#markup'] .= '<div class="col-md-12 text-right">';
7474

7575
if (!in_array("authenticated", $roles)) {
76-
$build['user_account_block']['#markup'] .= Link::fromTextAndUrl($this->t('Register'), Url::fromRoute('user.register', [], ['attributes' => ['class' => 'btn btn-default']]))->toString() . "\n";
76+
$build['user_account_block']['#markup'] .= Link::fromTextAndUrl($this->t('Register'), Url::fromRoute('user.register', [], [
77+
'attributes' => ['class' => 'btn btn-default'],
78+
]))->toString() . "\n";
7779
$build['user_account_block']['#markup'] .= Link::fromTextAndUrl($this->t('Sign in'), Url::fromRoute('user.login', [], ['attributes' => ['class' => 'btn btn-primary']]))->toString() . "\n";
7880
}
7981
else {
8082
$build['user_account_block']['#markup'] .= '<p class="mrgn-rght-sm display-inline">' . $this->t('Signed in as') . '<span class="wb-so-uname">' . ' ' . $account_name . '</span></p>';
81-
$build['user_account_block']['#markup'] .= Link::fromTextAndUrl($this->t('Account settings'), Url::fromRoute('user.page', [], ['attributes' => ['class' => 'btn btn-default', 'role' => 'button']]))->toString() . "\n";
82-
$build['user_account_block']['#markup'] .= Link::fromTextAndUrl($this->t('Sign out'), Url::fromRoute('user.logout', [], ['attributes' => ['class' => 'btn btn-primary', 'role' => 'button']]))->toString() . "\n";
83+
$build['user_account_block']['#markup'] .= Link::fromTextAndUrl($this->t('Account settings'), Url::fromRoute('user.page', [], [
84+
'attributes' => ['class' => 'btn btn-default', 'role' => 'button'],
85+
]))->toString() . "\n";
86+
$build['user_account_block']['#markup'] .= Link::fromTextAndUrl($this->t('Sign out'), Url::fromRoute('user.logout', [], [
87+
'attributes' => ['class' => 'btn btn-primary', 'role' => 'button'],
88+
]))->toString() . "\n";
8389
}
8490

8591
$build['user_account_block']['#markup'] .= '</div></section>';

src/Plugin/Condition/PanelsTitle.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ public function evaluate() {
222222
*/
223223
public function summary() {
224224
if (!empty($this->configuration['is_panelized'])) {
225-
return t('Is a panelized page with a title');
225+
return $this->t('Is a panelized page with a title');
226226
}
227227
}
228228

src/TwigExtension/LibraryTwig.php

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
namespace Drupal\wxt_library\TwigExtension;
44

5+
/**
6+
* Provides a twig extension for WxT.
7+
*/
58
class LibraryTwig extends \Twig_Extension {
69

710
/**

tests/src/Kernel/LibraryTest.php

+6
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,19 @@ class LibraryTest extends KernelTestBase {
3838
*/
3939
protected $pluginManager;
4040

41+
/**
42+
* Setup the test.
43+
*/
4144
protected function setUp(): void {
4245
parent::setUp();
4346

4447
$this->installConfig('wxt_library');
4548
$this->pluginManager = $this->container->get('wxt_library.service_wxt');
4649
}
4750

51+
/**
52+
* Test the library.
53+
*/
4854
public function testLibrary() {
4955
$this->assertSame('wet_boew', $this->pluginManager->getLibraryName());
5056
$this->assertSame('/libraries/theme-wet-boew', $this->pluginManager->getLibraryPath());

wxt_library.module

+6-5
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ function _wxt_library_check_theme() {
121121
function _wxt_library_check_url() {
122122
// Make it possible deactivate bootstrap with
123123
// parameter ?wxt_library=no in the url.
124-
if (isset($_GET['wxt_library']) && $_GET['wxt_library'] == 'no') {
124+
$query_string = \Drupal::service('request_stack')->getCurrentRequest()->query->get('wxt_library');
125+
if (isset($query_string) && $query_string == 'no') {
125126
return FALSE;
126127
}
127128

@@ -181,12 +182,12 @@ function _wxt_library_options() {
181182
/**
182183
* Gets the path of a library.
183184
*
184-
* @param $name
185+
* @param string $name
185186
* The machine name of a library to return the path for.
186-
* @param $base_path
187+
* @param string $base_path
187188
* Whether to prefix the resulting path with base_path().
188189
*
189-
* @return
190+
* @return string
190191
* The path to the specified library or FALSE if the library wasn't found.
191192
*/
192193
function _wxt_library_get_path($name, $base_path = FALSE) {
@@ -218,7 +219,7 @@ function _wxt_library_get_path($name, $base_path = FALSE) {
218219
* in both the site-wide directory and site-specific directory, only the
219220
* site-specific version will be listed.
220221
*
221-
* @return
222+
* @return array
222223
* A list of library directories.
223224
*/
224225
function _wxt_library_get_libraries() {

0 commit comments

Comments
 (0)