You are here

public function HMSNaturalLanguageFormatter::settingsForm in HMS Field 8

Returns a form to configure settings for the formatter.

Invoked from \Drupal\field_ui\Form\EntityDisplayFormBase to allow administrators to configure the formatter. The field_ui module takes care of handling submitted form values.

Parameters

array $form: The form where the settings form is being included in.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form elements for the formatter settings.

Overrides FormatterBase::settingsForm

File

src/Plugin/Field/FieldFormatter/HMSNaturalLanguageFormatter.php, line 72
Contains \Drupal\hms_field\Plugin\Field\FieldFormatter\HMSNaturalLanguageFormatter.

Class

HMSNaturalLanguageFormatter
Plugin implementation of the 'hms_natural_language_formatter' formatter.

Namespace

Drupal\hms_field\Plugin\Field\FieldFormatter

Code

public function settingsForm(array $form, FormStateInterface $form_state) {
  $elements = parent::settingsForm($form, $form_state);
  $options = array();
  $factors = $this->hms_service
    ->factor_map(TRUE);
  $order = $this->hms_service
    ->factor_map();
  arsort($order, SORT_NUMERIC);
  foreach ($order as $factor => $info) {
    $options[$factor] = t($factors[$factor]['label multiple']);
  }
  $elements['display_formats'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Display fragments'),
    '#options' => $options,
    '#description' => t('Formats that are displayed in this field'),
    '#default_value' => $this
      ->getSetting('display_formats'),
    '#required' => TRUE,
  );
  $elements['separator'] = array(
    '#type' => 'textfield',
    '#title' => t('Separator'),
    '#description' => t('Separator used between fragments'),
    '#default_value' => $this
      ->getSetting('separator'),
    '#required' => TRUE,
  );
  $elements['last_separator'] = array(
    '#type' => 'textfield',
    '#title' => t('Last separator'),
    '#description' => t('Separator used between the last 2 fragments'),
    '#default_value' => $this
      ->getSetting('last_separator'),
    '#required' => FALSE,
  );
  return $elements;
}