Skip to content

Commit 0c22c65

Browse files
feat: add no follow option in the links of Search Results Pager Block (Islandora#90)
1 parent cb4d7e6 commit 0c22c65

3 files changed

Lines changed: 30 additions & 2 deletions

File tree

config/schema/advanced_search.schema.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ advanced_search.settings:
4343
sequence:
4444
type: string
4545
label: Field identifier
46+
no_follow:
47+
type: integer
48+
label: Add rel="nofollow" attribute in links
4649

4750
block.settings.search_block:
4851
type: block_settings

src/Form/SettingsForm.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ class SettingsForm extends ConfigFormBase {
6060

6161
const QUERY_FIELDS = 'query_fields';
6262

63+
const NO_FOLLOW = 'no_follow';
64+
6365
/**
6466
* {@inheritdoc}
6567
*/
@@ -277,6 +279,19 @@ public function buildForm(array $form, FormStateInterface $form_state) {
277279
'#min' => 1,
278280
];
279281

282+
/* -------------------------
283+
* No follow option
284+
* ------------------------- */
285+
$form['no-follow'] = [
286+
'#type' => 'fieldset',
287+
'#title' => $this->t("No Follow Block"),
288+
];
289+
$form['no-follow'][self::NO_FOLLOW] = [
290+
'#type' => 'checkbox',
291+
'#title' => $this->t('Add rel="nofollow" attribute in links'),
292+
'#default_value' => self::getConfig(self::NO_FOLLOW, 0),
293+
];
294+
280295
return parent::buildForm($form, $form_state);
281296
}
282297

@@ -300,6 +315,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
300315
->set(self::DISPLAY_GRID_FLAG, $form_state->getValue(self::DISPLAY_GRID_FLAG))
301316
->set(self::DISPLAY_DEFAULT, $form_state->getValue(self::DISPLAY_DEFAULT))
302317
->set(self::QUERY_FIELDS, $query_fields)
318+
->set(self::NO_FOLLOW, $form_state->getValue(self::NO_FOLLOW))
303319
->save();
304320

305321
parent::submitForm($form, $form_state);

src/Plugin/Block/SearchResultsPagerBlock.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ protected function buildResultsSummary(ViewExecutable $view_executable) {
236236
* A renderable array representing the results per page portion of pager.
237237
*/
238238
protected function buildResultsPerPageLinks(SqlBase $pager, array $query_parameters) {
239+
$config = $this->configFactory->get(SettingsForm::CONFIG_NAME);
239240
$active_items_per_page = $query_parameters['items_per_page'] ?? $pager->options['items_per_page'];
240241
$items_per_page_options = array_map(function ($value) {
241242
return trim($value);
@@ -252,7 +253,7 @@ protected function buildResultsPerPageLinks(SqlBase $pager, array $query_paramet
252253
'absolute' => TRUE,
253254
]);
254255
$active = $items_per_page == $active_items_per_page;
255-
$items[] = [
256+
$item = [
256257
'#type' => 'link',
257258
'#url' => $url,
258259
'#title' => $items_per_page,
@@ -267,6 +268,10 @@ protected function buildResultsPerPageLinks(SqlBase $pager, array $query_paramet
267268
'class' => $active ? ['pager__item', 'is-active'] : ['pager__item'],
268269
],
269270
];
271+
if (!empty($config->get(SettingsForm::NO_FOLLOW))) {
272+
$item['#attributes']['rel'] = 'nofollow';
273+
}
274+
$items[] = $item;
270275
}
271276
return [
272277
'#theme' => 'item_list',
@@ -333,7 +338,7 @@ protected function buildDisplayLinks(array $query_parameters) {
333338
]);
334339
$text = "<i class='fa {$options['icon']}' aria-hidden='true'>&nbsp;</i><span class='display-mode'>{$options['title']}</span>";
335340
$active = $active_display == $display;
336-
$items[] = [
341+
$item = [
337342
'#type' => 'link',
338343
'#url' => $url,
339344
'#title' => Markup::create($text),
@@ -348,6 +353,10 @@ protected function buildDisplayLinks(array $query_parameters) {
348353
'class' => $active ? ['pager__item', 'is-active'] : ['pager__item'],
349354
],
350355
];
356+
if (!empty($config->get(SettingsForm::NO_FOLLOW))) {
357+
$item['#attributes']['rel'] = 'nofollow';
358+
}
359+
$items[] = $item;
351360
}
352361

353362
if (count($items) > 0) {

0 commit comments

Comments
 (0)