Drupal 8  8.0.2
TimestampAgoFormatter Class Reference
Inheritance diagram for TimestampAgoFormatter:

Public Member Functions

 __construct ($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, $label, $view_mode, array $third_party_settings, DateFormatterInterface $date_formatter, Request $request)
 
 settingsForm (array $form, FormStateInterface $form_state)
 
 settingsSummary ()
 
 viewElements (FieldItemListInterface $items, $langcode)
 
- Public Member Functions inherited from FormatterBase
 __construct ($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, $label, $view_mode, array $third_party_settings)
 
 view (FieldItemListInterface $items, $langcode=NULL)
 
 settingsForm (array $form, FormStateInterface $form_state)
 
 settingsSummary ()
 
 prepareView (array $entities_items)
 
- Public Member Functions inherited from PluginSettingsBase
 getSettings ()
 
 getSetting ($key)
 
 setSettings (array $settings)
 
 setSetting ($key, $value)
 
 getThirdPartySettings ($module=NULL)
 
 getThirdPartySetting ($module, $key, $default=NULL)
 
 setThirdPartySetting ($module, $key, $value)
 
 unsetThirdPartySetting ($module, $key)
 
 getThirdPartyProviders ()
 
 calculateDependencies ()
 
 onDependencyRemoval (array $dependencies)
 
- Public Member Functions inherited from PluginInspectionInterface
 getPluginId ()
 
 getPluginDefinition ()
 

Static Public Member Functions

static create (ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition)
 
static defaultSettings ()
 
- Static Public Member Functions inherited from FormatterBase
static isApplicable (FieldDefinitionInterface $field_definition)
 
- Static Public Member Functions inherited from PluginSettingsBase
static defaultSettings ()
 

Protected Member Functions

 formatTimestamp ($timestamp)
 
- Protected Member Functions inherited from FormatterBase
 getFieldSettings ()
 
 getFieldSetting ($setting_name)
 
- Protected Member Functions inherited from PluginSettingsBase
 mergeDefaults ()
 

Protected Attributes

 $dateFormatter
 
 $request
 
- Protected Attributes inherited from FormatterBase
 $fieldDefinition
 
 $settings
 
 $label
 
 $viewMode
 
- Protected Attributes inherited from PluginSettingsBase
 $settings = array()
 
 $thirdPartySettings = array()
 
 $defaultSettingsMerged = FALSE
 

Detailed Description

Plugin implementation of the 'timestamp' formatter as time ago.

( id = "timestamp_ago", label = ("Time ago"), field_types = { "timestamp", "created", "changed", } )

Constructor & Destructor Documentation

__construct (   $plugin_id,
  $plugin_definition,
FieldDefinitionInterface  $field_definition,
array  $settings,
  $label,
  $view_mode,
array  $third_party_settings,
DateFormatterInterface  $date_formatter,
Request  $request 
)

Constructs a TimestampAgoFormatter object.

Parameters
string$plugin_idThe plugin_id for the formatter.
mixed$plugin_definitionThe plugin implementation definition.
\Drupal\Core\Field\FieldDefinitionInterface$field_definitionThe definition of the field to which the formatter is associated.
array$settingsThe formatter settings.
string$labelThe formatter label display setting.
string$view_modeThe view mode.
array$third_party_settingsAny third party settings.
\Drupal\Core\Datetime\DateFormatterInterface$date_formatterThe date formatter service.
\Symfony\Component\HttpFoundation\Request$requestThe current request.

References Drupal\request().

Here is the call graph for this function:

Member Function Documentation

static create ( ContainerInterface  $container,
array  $configuration,
  $plugin_id,
  $plugin_definition 
)
static

{Creates an instance of the plugin.

Parameters
\Symfony\Component\DependencyInjection\ContainerInterface$containerThe container to pull out services used in the plugin.
array$configurationA configuration array containing information about the plugin instance.
string$plugin_idThe plugin ID for the plugin instance.
mixed$plugin_definitionThe plugin implementation definition.
Returns
static Returns an instance of this plugin.
}

Implements ContainerFactoryPluginInterface.

static defaultSettings ( )
static

{Defines the default settings for this plugin.

Returns
array A list of default settings, keyed by the setting name.
}

Implements PluginSettingsInterface.

formatTimestamp (   $timestamp)
protected

Formats a timestamp.

Parameters
int$timestampA UNIX timestamp to format.
Returns
string The formatted timestamp string using the past or future format setting.

References SafeMarkup\format(), PluginSettingsBase\getSetting(), and Drupal\request().

Referenced by TimestampAgoFormatter\settingsSummary(), and TimestampAgoFormatter\viewElements().

Here is the call graph for this function:

Here is the caller graph for this function:

settingsForm ( array  $form,
FormStateInterface  $form_state 
)

{Returns a form to configure settings for the formatter.Invoked from to allow administrators to configure the formatter. The field_ui module takes care of handling submitted form values.

Parameters
array$formThe form where the settings form is being included in.
\Drupal\Core\Form\FormStateInterface$form_stateThe current state of the form.
Returns
array The form elements for the formatter settings.
}

Implements FormatterInterface.

References PluginSettingsBase\getSetting(), and t().

Here is the call graph for this function:

settingsSummary ( )

{Returns a short summary for the current formatter settings.If an empty result is returned, a UI can still be provided to display a settings form in case the formatter has configurable settings.

Returns
string[] A short summary of the formatter settings.
}

Implements FormatterInterface.

References TimestampAgoFormatter\formatTimestamp(), and t().

Here is the call graph for this function:

viewElements ( FieldItemListInterface  $items,
  $langcode 
)

{Builds a renderable array for a field value.

Parameters
\Drupal\Core\Field\FieldItemListInterface$itemsThe field values to be rendered.
string$langcodeThe language that should be used to render the field.
Returns
array A renderable array for $items, as an array of child elements keyed by consecutive numeric indexes starting from 0.
}

Implements FormatterInterface.

References TimestampAgoFormatter\formatTimestamp(), and t().

Here is the call graph for this function:


The documentation for this class was generated from the following file: