public function DateFieldFormatIntervalFormatter::settingsForm in Date 8
Implements Drupal\field\Plugin\Type\Formatter\FormatterInterface::settingsForm().
File
- date_field/
lib/ Drupal/ date_field/ Plugin/ field/ formatter/ DateFieldFormatIntervalFormatter.php, line 127 - Definition of Drupal\date_field\Plugin\field\formatter\DateFieldFormatIntervalFormatter.
Class
- DateFieldFormatIntervalFormatter
- Plugin implementation of the 'format_interval'' formatter.
Namespace
Drupal\date_field\Plugin\field\formatterCode
public function settingsForm(array $form, array &$form_state) {
$field = $this->field;
$instance = $this->instance;
$settings = $this->settings;
$view_mode = $this->viewMode;
$weight = $this->weight;
$label = $this->label;
$definition = $this
->getDefinition();
$formatter = $definition['id'];
$element = array();
$element['interval'] = array(
'#title' => t('Interval'),
'#description' => t("How many time units should be shown in the 'time ago' string."),
'#type' => 'select',
'#options' => drupal_map_assoc(range(1, 6)),
'#default_value' => $settings['interval'],
'#weight' => 0,
);
// Uses the same options used by Views format_interval.
$options = array(
'raw time ago' => t('Time ago'),
'time ago' => t('Time ago (with "ago" appended)'),
'raw time hence' => t('Time hence'),
'time hence' => t('Time hence (with "hence" appended)'),
'raw time span' => t('Time span (future dates have "-" prepended)'),
'inverse time span' => t('Time span (past dates have "-" prepended)'),
'time span' => t('Time span (with "ago/hence" appended)'),
);
$element['interval_display'] = array(
'#title' => t('Display'),
'#description' => t("How to display the time ago or time hence for this field."),
'#type' => 'select',
'#options' => $options,
'#default_value' => $settings['interval_display'],
'#weight' => 0,
);
$context = array(
'field' => $field,
'instance' => $instance,
'view_mode' => $view_mode,
'formatter' => $formatter,
'settings' => $settings,
);
drupal_alter('date_field_formatter_settings_form', $element, $form_state, $context);
return $element;
}