diff --git a/modules/oe_whitelabel_helper/README.md b/modules/oe_whitelabel_helper/README.md index 70f129d33..9d06a10c5 100644 --- a/modules/oe_whitelabel_helper/README.md +++ b/modules/oe_whitelabel_helper/README.md @@ -19,11 +19,6 @@ Enables the [OpenEuropa Multilingual](https://github.com/openeuropa/oe_multiling 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. ``` diff --git a/modules/oe_whitelabel_helper/src/TwigExtension/TwigExtension.php b/modules/oe_whitelabel_helper/src/TwigExtension/TwigExtension.php index d900fe6a2..221668793 100644 --- a/modules/oe_whitelabel_helper/src/TwigExtension/TwigExtension.php +++ b/modules/oe_whitelabel_helper/src/TwigExtension/TwigExtension.php @@ -5,9 +5,7 @@ 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; /** @@ -29,15 +27,6 @@ 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} */ @@ -48,63 +37,6 @@ 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. *