-class DateTimeTimeAgoFormatter extends FormatterBase implements ContainerFactoryPluginInterface {
-
- /**
- * The date formatter service.
- *
- * @var \Drupal\Core\Datetime\DateFormatterInterface
- */
- protected $dateFormatter;
-
- /**
- * The current Request object.
- *
- * @var \Symfony\Component\HttpFoundation\Request
- */
- protected $request;
-
- /**
- * Constructs a DateTimeTimeAgoFormatter object.
- *
- * @param string $plugin_id
- * The plugin_id for the formatter.
- * @param mixed $plugin_definition
- * The plugin implementation definition.
- * @param \Drupal\Core\Field\FieldDefinitionInterface $field_definition
- * The definition of the field to which the formatter is associated.
- * @param array $settings
- * The formatter settings.
- * @param string $label
- * The formatter label display setting.
- * @param string $view_mode
- * The view mode.
- * @param array $third_party_settings
- * Third party settings.
- * @param \Drupal\Core\Datetime\DateFormatterInterface $date_formatter
- * The date formatter service.
- * @param \Symfony\Component\HttpFoundation\Request $request
- * The current request.
- */
- public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, $label, $view_mode, array $third_party_settings, DateFormatterInterface $date_formatter, Request $request) {
- parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings, $label, $view_mode, $third_party_settings);
-
- $this->dateFormatter = $date_formatter;
- $this->request = $request;
- }
-
- /**
- * {@inheritdoc}
- */
- public static function defaultSettings() {
- $settings = [
- 'future_format' => '@interval hence',
- 'past_format' => '@interval ago',
- 'granularity' => 2,
- ] + parent::defaultSettings();
-
- return $settings;
- }
-
- /**
- * {@inheritdoc}
- */
- public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
- return new static(
- $plugin_id,
- $plugin_definition,
- $configuration['field_definition'],
- $configuration['settings'],
- $configuration['label'],
- $configuration['view_mode'],
- $configuration['third_party_settings'],
- $container->get('date.formatter'),
- $container->get('request_stack')->getCurrentRequest()
- );
- }