Skip to content
Snippets Groups Projects

#3200255 Create an "Is All Date" twig function

1 file
+ 27
0
Compare changes
  • Side-by-side
  • Inline
@@ -5,6 +5,7 @@ namespace Drupal\smart_date\TwigExtension;
use Drupal\smart_date\SmartDatePluginTrait;
use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;
use Twig\TwigFunction;
/**
* Custom twig functions.
@@ -34,6 +35,15 @@ class SmartDateFormat extends AbstractExtension {
];
}
/**
* {@inheritDoc}
*/
public function getFunctions() {
return [
new TwigFunction('is_all_day', $this->smartDateIsAllDay(...)),
];
}
/**
* Function to apply a Smart Date Format to input.
*
@@ -104,4 +114,21 @@ class SmartDateFormat extends AbstractExtension {
return 'smart_date_format.twig_extension';
}
/**
* Evaluates whether or not a provided range is "all day".
*
* @param object $start_ts
* A timestamp.
* @param object $end_ts
* A timestamp.
* @param string|null $timezone
* An optional timezone override.
*
* @return bool
* Whether or not the timestamps are considered all day by Smart Date.
*/
public function smartDateIsAllDay($start_ts, $end_ts, $timezone = NULL): bool {
return static::isAllDay($start_ts, $end_ts, $timezone);
}
}
Loading