You are here

public function DateDefaultFormatter::settingsForm in Date 8

Implements Drupal\field\Plugin\Type\Formatter\FormatterInterface::settingsForm().

File

lib/Drupal/date/Plugin/field/formatter/DateDefaultFormatter.php, line 131
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 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['format_type'] = array(
    '#title' => t('Choose how users view dates and times:'),
    '#type' => 'select',
    '#options' => date_format_type_options(),
    '#default_value' => $settings['format_type'],
    '#description' => t('To add or edit options, visit <a href="@date-time-page">Date and time settings</a>.', array(
      '@date-time-page' => url('admin/config/regional/date-time'),
    )),
    '#weight' => 0,
  );
  $element['fromto'] = array(
    '#title' => t('Display:'),
    '#type' => 'select',
    '#options' => array(
      'both' => t('Both Start and End dates'),
      'value' => t('Start date only'),
      'value2' => t('End date only'),
    ),
    '#access' => $field['settings']['todate'],
    '#default_value' => $settings['fromto'],
    '#weight' => 1,
  );

  // Make the string translatable by keeping it as a whole rather than
  // translating prefix and suffix separately.
  list($prefix, $suffix) = explode('@count', t('Show @count value(s)'));
  $element['multiple_number'] = array(
    '#type' => 'textfield',
    '#title' => t('Multiple values:'),
    '#size' => 5,
    '#field_prefix' => $prefix,
    '#field_suffix' => $suffix,
    '#default_value' => $settings['multiple_number'],
    '#weight' => 2,
    '#access' => $field['cardinality'] == FIELD_CARDINALITY_UNLIMITED || $field['cardinality'] > 1,
    '#description' => t('Identify a specific number of values to display, or leave blank to show all values.'),
  );
  list($prefix, $suffix) = explode('@isodate', t('starting from @isodate'));
  $element['multiple_from'] = array(
    '#type' => 'textfield',
    '#size' => 15,
    '#field_prefix' => $prefix,
    '#field_suffix' => $suffix,
    '#default_value' => $settings['multiple_from'],
    '#weight' => 3,
    '#access' => $field['cardinality'] == FIELD_CARDINALITY_UNLIMITED || $field['cardinality'] > 1,
  );
  list($prefix, $suffix) = explode('@isodate', t('ending with @isodate'));
  $element['multiple_to'] = array(
    '#type' => 'textfield',
    '#size' => 15,
    '#field_prefix' => $prefix,
    '#field_suffix' => $suffix,
    '#default_value' => $settings['multiple_to'],
    '#weight' => 4,
    '#access' => $field['cardinality'] == FIELD_CARDINALITY_UNLIMITED || $field['cardinality'] > 1,
    '#description' => t('Identify specific start and/or end dates in the format YYYY-MM-DDTHH:MM:SS, or leave blank for all available dates.'),
  );
  $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;
}