Skip to content

Commit

Permalink
Merge pull request #42 from openeuropa/OEL-719
Browse files Browse the repository at this point in the history
OEL-719: Adapt search changes.
  • Loading branch information
drishu authored Nov 3, 2021
2 parents 8a08f4c + 6890b2e commit 1ce75fc
Show file tree
Hide file tree
Showing 13 changed files with 112 additions and 64 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"drupal/core": "^8.9 || ^9.1",
"drupal/ui_patterns": "^1.0",
"drupal/ui_patterns_settings": "^1.0",
"openeuropa/oe_bootstrap_theme": "0.281020211203"
"openeuropa/oe_bootstrap_theme": "0.031120211510"
},
"require-dev": {
"composer/installers": "^1.11",
Expand Down
17 changes: 17 additions & 0 deletions modules/oe_whitelabel_helper/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,23 @@ Enables the [OpenEuropa Authentication](https://github.com/openeuropa/oe_authent
Enables the [OpenEuropa Multilingual](https://github.com/openeuropa/oe_multilingual) module.
The language switcher block is themed out of the box.

### Twig helpers
#### bcl_timeago filter
Filters a timestamp in "time ago" format, result can be something like "8 hours ago".
```
node.getCreatedTime|bcl_timeago
```
#### bcl_footer_links function
Processes oe_corporate_blocks links to make them compatible with BCL formatting.
```
bcl_footer_links(links)
```
#### bcl_block function
Builds the render array for a block.
```
bcl_block(block)
```

## Requirements

To be able to enable this module you will have to provide the dependent modules in your projects composer.json
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ class FloatEndSortWidget extends DefaultWidget {
public function exposedFormAlter(array &$form, FormStateInterface $form_state) {
parent::exposedFormAlter($form, $form_state);
$form['#attributes']['class'][] = 'float-lg-end';
$form['#attributes']['class'][] = 'd-md-block';
$form['#attributes']['class'][] = 'd-none';
$form['#attributes']['class'][] = 'd-md-flex';
$form['#attributes']['class'][] = 'align-items-baseline';
}

}
68 changes: 68 additions & 0 deletions modules/oe_whitelabel_helper/src/TwigExtension/TwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
namespace Drupal\oe_whitelabel_helper\TwigExtension;

use Drupal\Core\Cache\CacheableDependencyInterface;
use Drupal\Core\StringTranslation\PluralTranslatableMarkup;
use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;
use Twig\TwigFunction;

/**
Expand All @@ -27,6 +29,15 @@ public function __construct(CacheableDependencyInterface $plugin_manager_block)
$this->pluginManagerBlock = $plugin_manager_block;
}

/**
* {@inheritdoc}
*/
public function getFilters(): array {
return [
new TwigFilter('bcl_timeago', [$this, 'bclTimeAgo']),
];
}

/**
* {@inheritdoc}
*/
Expand All @@ -37,6 +48,63 @@ public function getFunctions(): array {
];
}

/**
* Filters a timestamp in "time ago" format.
*
* @param string $timestamp
* Datetime to be parsed.
*
* @return \Drupal\Core\StringTranslation\PluralTranslatableMarkup
* The translated time ago string.
*/
public function bclTimeAgo(string $timestamp): PluralTranslatableMarkup {
$time = \Drupal::time()->getCurrentTime() - $timestamp;
$time_ago = new PluralTranslatableMarkup(0, 'N/A', 'N/A');
$units = [
31536000 => [
'singular' => '@number year ago',
'plural' => '@number years ago',
],
2592000 => [
'singular' => '@number month ago',
'plural' => '@number months ago',
],
604800 => [
'singular' => '@number week ago',
'plural' => '@number weeks ago',
],
86400 => [
'singular' => '@number day ago',
'plural' => '@number days ago',
],
3600 => [
'singular' => '@number hour ago',
'plural' => '@number hours ago',
],
60 => [
'singular' => '@number minute ago',
'plural' => '@number minutes ago',
],
1 => [
'singular' => '@number second ago',
'plural' => '@number seconds ago',
],
];

foreach ($units as $unit => $format) {
if ($time < $unit) {
continue;
}

$number_of_units = floor($time / $unit);
$time_ago = \Drupal::translation()
->formatPlural($number_of_units, $format['singular'], $format['plural'], ['@number' => $number_of_units]);
break;
}

return $time_ago;
}

/**
* Processes footer links to make them compatible with BCL formatting.
*
Expand Down
11 changes: 8 additions & 3 deletions oe_whitelabel.theme
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,23 @@ function oe_whitelabel_preprocess_links__language_block(&$variables) {
*/
function oe_whitelabel_form_facets_form_alter(&$form, FormStateInterface $form_state, $form_id) {
if (isset($form['actions'])) {
$form['actions']['#attributes']['class'][] = 'mt-4';
$action_classes = ['mt-4', 'd-grid', 'gap-4', 'd-md-block'];
foreach ($action_classes as $action_class) {
if (!isset($action_class, $form['actions']['#attributes']['class']) || !in_array($action_class, $form['actions']['#attributes']['class'], TRUE)) {
$form['actions']['#attributes']['class'][] = $action_class;
}
}
}
if (isset($form['actions']['submit'])) {
$submit_classes = ['me-2', 'btn', 'btn-primary'];
$submit_classes = ['me-md-3', 'btn', 'btn-primary', 'btn-md'];
foreach ($submit_classes as $submit_class) {
if (!isset($submit_class, $form['actions']['submit']['#attributes']['class']) || !in_array($submit_class, $form['actions']['submit']['#attributes']['class'], TRUE)) {
$form['actions']['submit']['#attributes']['class'][] = $submit_class;
}
}
}
if (isset($form['actions']['reset'])) {
$reset_classes = ['btn', 'btn-secondary'];
$reset_classes = ['btn', 'btn-light', 'btn-md'];
foreach ($reset_classes as $reset_class) {
if (!isset($form['actions']['reset']['#attributes']['class']) || !in_array($reset_class, $form['actions']['reset']['#attributes']['class'], TRUE)) {
$form['actions']['reset']['#attributes']['class'][] = $reset_class;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
'links': bcl_footer_links(corporate_footer.class_navigation),
}
] %}
<footer class="ec__footer bcl-footer">
<footer class="ec__footer bcl-footer mt-4">
<div class="container">
{{ pattern('footer', {
'variant': 'ec',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
'eu_institutions_links': bcl_footer_links(corporate_footer.institution_links)
}
] %}
<footer class="bcl-footer">
<footer class="bcl-footer mt-4">
<div class="container">
{{ pattern('footer', {
'variant': 'eu',
Expand Down
8 changes: 4 additions & 4 deletions templates/overrides/page/page.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@
{% if page.content or page.content_top %}
<div{{ attributes.addClass(grid_classes) }}>
{% if page.content_top %}
<div class="mb-3 clearfix">
{{ page.content_top }}
</div>
<hr class="d-none d-md-block mb-4">
<div class="mb-3 clearfix">
{{ page.content_top }}
</div>
<hr class="d-none d-md-block mt-4 mb-4-75">
{% endif %}

{{ page.content }}
Expand Down
9 changes: 6 additions & 3 deletions templates/overrides/search/block--facets-form.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
'url': content.actions['reset']['#url'].toString(),
'style': 'secondary',
'attributes': extra_attributes.addClass('ms-2')
})
})
%}
{% set actions = content.actions %}
{% set actions = actions|merge({('reset'): reset}) %}
Expand All @@ -49,7 +49,7 @@
'label': label,
'heading': 4,
'extra_classes': "mb-lg-4",
},
},
'attributes': attributes.addClass('bcl-offcanvas'),
'offcanvas_id': 'bcl-offcanvas',
'body': content,
Expand All @@ -61,6 +61,9 @@
'extra_classes_header': "p-lg-0",
'with_trigger': true,
'toggle_button_label': label,
'icon_name': 'sliders'
'icon_position': 'before',
'icon': {
'name': 'filter',
},
}) }}
{% endblock %}
3 changes: 2 additions & 1 deletion templates/overrides/search/facets-result-item.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
* @ingroup themeable
*/
#}
{% set attributes = create_attribute({'class': ['me-2']}) %}
{% set attributes = create_attribute({'class': ['me-2', 'fs-6']}) %}
{{ pattern('badge', {
'background': 'light',
'label': value,
'assistive_text': assistive_text,
'dismissible': true,
Expand Down
27 changes: 0 additions & 27 deletions templates/overrides/search/pager.html.twig

This file was deleted.

21 changes: 0 additions & 21 deletions templates/overrides/search/views-mini-pager.html.twig

This file was deleted.

2 changes: 1 addition & 1 deletion tests/src/Kernel/AuthenticationBlockTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function testBlockRendering(): void {
$actual = $crawler->filter('.oe-authentication');
$this->assertCount(1, $actual);
$icon = $actual->filter('svg');
$this->assertSame('bi icon--xs', $icon->attr('class'));
$this->assertSame('ms-2-5 bi icon--xs', $icon->attr('class'));
$use = $icon->filter('use');
$expected = '/themes/contrib/oe_bootstrap_theme/assets/icons/bootstrap-icons.svg#person-fill';
$this->assertSame($expected, $use->attr('xlink:href'));
Expand Down

0 comments on commit 1ce75fc

Please sign in to comment.