public function MomentFormat::moment in Twig Extender 8.2
Same name and namespace in other branches
- 8.4 modules/twig_extender_extras/src/Plugin/TwigPlugin/MomentFormat.php \Drupal\twig_extender_extras\Plugin\TwigPlugin\MomentFormat::moment()
- 8.3 modules/twig_extender_extras/src/Plugin/TwigPlugin/MomentFormat.php \Drupal\twig_extender_extras\Plugin\TwigPlugin\MomentFormat::moment()
- 4.x modules/twig_extender_extras/src/Plugin/TwigPlugin/MomentFormat.php \Drupal\twig_extender_extras\Plugin\TwigPlugin\MomentFormat::moment()
Format a date with moment php.
Parameters
mixed $date: The element array whose children are to be identified. Passed by reference.
string $format: Boolean to indicate whether the children should be sorted by weight.
mixed $timezone: Boolean to indicate whether the children should be sorted by weight.
mixed $js: Boolean to indicate whether the children should be sorted by weight.
Return value
array Array for render.
Throws
\Exception
File
- modules/
twig_extender_extras/ src/ Plugin/ TwigPlugin/ MomentFormat.php, line 38
Class
- MomentFormat
- Provide helper methods for Drupal render elements.
Namespace
Drupal\twig_extender_extras\Plugin\TwigPluginCode
public function moment($date, $format, $timezone = NULL, $js = FALSE) {
$moment = $this
->getMoment($date, $timezone);
$value = $moment
->format($format);
if ($js === TRUE) {
$value = $moment
->format($format, new MomentJs());
}
$build = [
'#cache' => [
'contexts' => [
'languages',
'timezone',
],
],
'#markup' => $value,
];
return $build;
}