Skip to content

Commit efb094d

Browse files
gitABGEO
authored andcommitted
Applied patch for Issue #3077333 by davitako: Add filter to currency block settings
1 parent 72362a3 commit efb094d

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

js/nbg-currency-settings.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* @file
3+
* NBG Currency block behaviors.
4+
*/
5+
(function ($, Drupal) {
6+
'use strict';
7+
8+
Drupal.behaviors.ngbCurrencyFilterByText = {
9+
attach: function (context, settings) {
10+
// Currency filter.
11+
$('input.currency-filter-search', context).once().on('input', function (e) {
12+
var value = $(this).val().toLowerCase();
13+
$(".nbg-currency")
14+
.closest('.form-type-checkbox')
15+
.filter(function () {
16+
$(this).toggle($(this).text().toLowerCase().indexOf(value) > -1)
17+
});
18+
})
19+
}
20+
};
21+
})(jQuery, Drupal);

nbg_currency.libraries.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,10 @@ nbg-currency:
22
css:
33
theme:
44
css/nbg-currency.css: {}
5+
6+
nbg-currency.settings:
7+
js:
8+
js/nbg-currency-settings.js: {}
9+
dependencies:
10+
- core/jquery
11+
- core/jquery.once

src/Plugin/Block/NBGCurrencyBlock.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,15 +197,41 @@ public function blockForm($form, FormStateInterface $form_state) {
197197
}
198198
}
199199

200+
// Container for filtering currencies.
201+
$form['nbg_currency'] = [
202+
'#type' => 'container',
203+
'#attributes' => [
204+
'class' => ['currency-filter'],
205+
],
206+
];
207+
208+
// Currency filter.
209+
$form['nbg_currency']['nbg_currency_filter'] = [
210+
'#type' => 'search',
211+
'#title' => $this->t('Filter currency'),
212+
'#size' => 30,
213+
'#placeholder' => $this->t('Filter by name'),
214+
'#description' => $this->t('Enter part of a currency'),
215+
'#attributes' => [
216+
'class' => ['currency-filter-search'],
217+
],
218+
];
219+
200220
// Create checkboxes group for Currency Codes.
201221
$form['nbg_currency_currencies'] = [
202222
'#type' => 'checkboxes',
203223
'#options' => $currencies,
204224
'#title' => $this->t('Currency Codes'),
205225
'#description' => $this->t('Select Currency Codes for displaying in block.'),
206226
'#default_value' => $config['nbg_currency_currencies'] ?? [],
227+
'#attributes' => [
228+
'class' => ['nbg-currency']
229+
]
207230
];
208231

232+
// Attach block settings library.
233+
$form['#attached']['library'][] = 'nbg_currency/nbg-currency.settings';
234+
209235
return $form;
210236
}
211237

0 commit comments

Comments
 (0)