You are here

public function DateDefaultFormatter::settingsSummary in Date 8

Settings summary for the default formatter.

File

lib/Drupal/date/Plugin/field/formatter/DateDefaultFormatter.php, line 219
Definition of Drupal\date\Plugin\field\formatter\DateDefaultFormatter.

Class

DateDefaultFormatter
Plugin implementation of the 'date_default' formatter.

Namespace

Drupal\date\Plugin\field\formatter

Code

public function settingsSummary() {
  $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'];
  $format_types = date_format_type_options();
  $summary = array();
  $format = FALSE;
  $format = t('Plain');
  if (!empty($format_types[$settings['format_type']])) {
    $format = $format_types[$settings['format_type']];
  }
  if ($format) {
    $summary[] = t('Display dates using the @format format', array(
      '@format' => $format,
    ));
  }
  else {
    $summary[] = t('Display dates using the default format because the specified format (@format) is not defined', array(
      '@format' => $settings['format_type'],
    ));
  }
  if (array_key_exists('fromto', $settings) && $field['settings']['todate']) {
    $options = array(
      'both' => t('Display both Start and End dates'),
      'value' => t('Display Start date only'),
      'value2' => t('Display End date only'),
    );
    $summary[] = $options[$settings['fromto']];
  }
  if (array_key_exists('multiple_number', $settings) && !empty($field['cardinality'])) {
    $summary[] = t('Show @count value(s) starting with @date1, ending with @date2', array(
      '@count' => !empty($settings['multiple_number']) ? $settings['multiple_number'] : t('all'),
      '@date1' => !empty($settings['multiple_from']) ? $settings['multiple_from'] : t('earliest'),
      '@date2' => !empty($settings['multiple_to']) ? $settings['multiple_to'] : t('latest'),
    ));
  }
  $context = array(
    'field' => $field,
    'instance' => $instance,
    'view_mode' => $view_mode,
    'formatter' => $formatter,
    'settings' => $settings,
  );
  drupal_alter('date_field_formatter_settings_summary', $summary, $context);
  return implode('<br />', $summary);
}