class MomentDifference in Twig Extender 4.x
Same name and namespace in other branches
- 8.4 modules/twig_extender_extras/src/Plugin/TwigPlugin/MomentDifference.php \Drupal\twig_extender_extras\Plugin\TwigPlugin\MomentDifference
- 8.2 modules/twig_extender_extras/src/Plugin/TwigPlugin/MomentDifference.php \Drupal\twig_extender_extras\Plugin\TwigPlugin\MomentDifference
- 8.3 modules/twig_extender_extras/src/Plugin/TwigPlugin/MomentDifference.php \Drupal\twig_extender_extras\Plugin\TwigPlugin\MomentDifference
Provide helper methods for Drupal render elements.
Plugin annotation
@TwigPlugin(
id = "twig_extender_moment_difference",
label = @Translation("Identifies the children of an element array, optionally sorted by weight."),
type = "filter",
name = "moment_difference",
function = "moment"
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\twig_extender\Plugin\Twig\TwigPluginBase implements TwigExtensionInterface
- class \Drupal\twig_extender_extras\Plugin\TwigPlugin\BaseMoment
- class \Drupal\twig_extender_extras\Plugin\TwigPlugin\MomentDifference
- class \Drupal\twig_extender_extras\Plugin\TwigPlugin\BaseMoment
- class \Drupal\twig_extender\Plugin\Twig\TwigPluginBase implements TwigExtensionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of MomentDifference
File
- modules/
twig_extender_extras/ src/ Plugin/ TwigPlugin/ MomentDifference.php, line 16
Namespace
Drupal\twig_extender_extras\Plugin\TwigPluginView source
class MomentDifference extends BaseMoment {
/**
* Get a difference between two dates.
*
* @param string $from
* Start date.
* @param mixed $to
* Date is relative to.
* @param mixed $operation
* Operation. Could be:
* relative|direction|seconds|minutes|hours|days|weeks|months|years.
* @param mixed $timezone
* Boolean to indicate whether the children should be sorted by weight.
*
* @return array
* String for render.
*
* @see https://github.com/fightbulc/moment.php
*/
public function moment($from, $to = NULL, $operation = 'direction', $timezone = NULL) {
$moment = $this
->getMoment($to, $timezone);
$from = $this
->getMoment($from, $timezone);
$funcCall = 'get' . ucfirst($operation);
return $moment
->from($from
->format())
->{$funcCall}();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
BaseMoment:: |
protected | function | Get default drupal timezone. | |
BaseMoment:: |
protected | function | Get current language. | |
BaseMoment:: |
protected | function | Get moment library. | |
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
public | function | 2 | |
DependencySerializationTrait:: |
public | function | 2 | |
MessengerTrait:: |
protected | property | The messenger. | 27 |
MessengerTrait:: |
public | function | Gets the messenger. | 27 |
MessengerTrait:: |
public | function | Sets the messenger. | |
MomentDifference:: |
public | function | Get a difference between two dates. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
2 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
PluginBase:: |
public | function | Constructs a \Drupal\Component\Plugin\PluginBase object. | 98 |
StringTranslationTrait:: |
protected | property | The string translation service. | 4 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
TwigPluginBase:: |
public | function |
Get type of the twig extension. Overrides TwigExtensionInterface:: |
|
TwigPluginBase:: |
public | function |
Get type of the twig extension. Overrides TwigExtensionInterface:: |
|
TwigPluginBase:: |
public | function |
Get type of the twig extension. Overrides TwigExtensionInterface:: |
|
TwigPluginBase:: |
public | function |
Get type of the twig extension. Overrides TwigExtensionInterface:: |