Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OEL-719: Adapt search changes. #42

Merged
merged 11 commits into from
Nov 3, 2021
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.291020212338"
},
"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 = time() - $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
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
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