public function ListFormatter::settingsForm in Text list formatter 8.2
Implements Drupal\field\Plugin\Type\Formatter\FormatterInterface::settingsForm().
File
- lib/
Drupal/ textformatter/ Plugin/ field/ formatter/ ListFormatter.php, line 50 - Definition of Drupal\textformatter\Plugin\field\formatter\List;
Class
- ListFormatter
- Plugin implementation of the 'text_default' formatter.
Namespace
Drupal\textformatter\Plugin\field\formatterCode
public function settingsForm(array $form, array &$form_state) {
$field_name = $this->field['field_name'];
$elements['type'] = array(
'#title' => t("List type"),
'#type' => 'select',
'#options' => $this
->listTypes(),
'#default_value' => $this
->getSetting('type'),
'#required' => TRUE,
);
$elements['comma_and'] = array(
'#type' => 'checkbox',
'#title' => t("Include 'and' before the last item"),
'#default_value' => $this
->getSetting('comma_and'),
'#states' => array(
'visible' => array(
':input[name="fields[' . $field_name . '][settings_edit_form][settings][type]"]' => array(
'value' => 'comma',
),
':input[name="fields[' . $field_name . '][settings_edit_form][settings][comma_override]"]' => array(
'checked' => FALSE,
),
),
),
);
$elements['comma_full_stop'] = array(
'#type' => 'checkbox',
'#title' => t("Append comma separated list with '.'"),
'#default_value' => $this
->getSetting('comma_full_stop'),
'#states' => array(
'visible' => array(
':input[name="fields[' . $field_name . '][settings_edit_form][settings][type]"]' => array(
'value' => 'comma',
),
':input[name="fields[' . $field_name . '][settings_edit_form][settings][comma_override]"]' => array(
'checked' => FALSE,
),
),
),
);
//Override Comma with custom separator.
$elements['comma_override'] = array(
'#type' => 'checkbox',
'#title' => t("Override comma separator"),
'#description' => t("Override the default comma separator with a custom separator string."),
'#default_value' => $this
->getSetting('comma_override'),
'#states' => array(
'visible' => array(
':input[name="fields[' . $field_name . '][settings_edit_form][settings][type]"]' => array(
'value' => 'comma',
),
),
),
);
$elements['separator_custom'] = array(
'#type' => 'textfield',
'#title' => t("Custom separator"),
'#description' => t("Override default comma separator with a custom separator string. You must add your own spaces in this string if you want them. @example", array(
'@example' => "E.g. ' + ', or ' => '",
)),
'#size' => 40,
'#default_value' => $this
->getSetting('separator_custom'),
'#states' => array(
'visible' => array(
':input[name="fields[' . $field_name . '][settings_edit_form][settings][comma_override]"]' => array(
'checked' => TRUE,
),
),
),
);
$elements['separator_custom_tag'] = array(
'#type' => 'select',
'#title' => t("separator HTML wrapper"),
'#description' => t("An HTML tag to wrap the separator in."),
'#options' => $this
->wrapperOptions(),
'#default_value' => $this
->getSetting('separator_custom_tag'),
'#states' => array(
'visible' => array(
':input[name="fields[' . $field_name . '][settings_edit_form][settings][comma_override]"]' => array(
'checked' => TRUE,
),
),
),
);
$elements['separator_custom_class'] = array(
'#title' => t("Separator classes"),
'#type' => 'textfield',
'#description' => t("A CSS class to use in the wrapper tag for the separator."),
'#default_value' => $this
->getSetting('separator_custom_class'),
'#element_validate' => array(
'_textformatter_validate_class',
),
'#states' => array(
'visible' => array(
':input[name="fields[' . $field_name . '][settings_edit_form][settings][comma_override]"]' => array(
'checked' => TRUE,
),
),
),
);
$elements['comma_tag'] = array(
'#type' => 'select',
'#title' => t("HTML wrapper"),
'#description' => t("An HTML tag to wrap the list in. The CSS class below will be added to this tag."),
'#options' => $this
->wrapperOptions(),
'#default_value' => $this
->getSetting('comma_tag'),
'#states' => array(
'visible' => array(
':input[name="fields[' . $field_name . '][settings_edit_form][settings][type]"]' => array(
'value' => 'comma',
),
),
),
);
$elements['class'] = array(
'#title' => t("List classes"),
'#type' => 'textfield',
'#size' => 40,
'#description' => t("A CSS class to use in the markup for the field list."),
'#default_value' => $this
->getSetting('class'),
'#element_validate' => array(
'_textformatter_validate_class',
),
);
// Taxonomy term ref fields only.
if ($this->field['type'] == 'taxonomy_term_reference') {
$elements['term_plain'] = array(
'#type' => 'checkbox',
'#title' => t("Display taxonomy terms as plain text (Not term links)."),
'#default_value' => $this
->getSetting('term_plain'),
);
}
$context = array(
'field' => $this->field,
'instance' => $this->instance,
'view_mode' => $this->viewMode,
);
drupal_alter('textformatter_field_formatter_settings_form', $form, $form_state, $context);
return $elements;
}