You are here

public function TaxonomyTermReferenceCsv::settingsForm in Taxonomy Formatter 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/TaxonomyTermReferenceCsv.php, line 44
Contains \Drupal\taxonomy_formatter\Plugin\Field\FieldFormatter\TaxonomyTermReferenceCsv.

Class

TaxonomyTermReferenceCsv
Plugin annotation @FieldFormatter( id = "taxonomy_term_reference_csv", label = @Translation("Delimited"), field_types = { "entity_reference" } )

Namespace

Drupal\taxonomy_formatter\Plugin\Field\FieldFormatter

Code

public function settingsForm(array $form, FormStateInterface $form_state) {
  $element = array();
  $element['links_option'] = array(
    '#type' => 'checkbox',
    '#title' => t('Links'),
    '#description' => t('When checked terms will be displayed as links'),
    '#default_value' => $this
      ->getSetting('links_option'),
  );
  $element['separator_option'] = array(
    '#type' => 'textfield',
    '#title' => t('Separator'),
    '#description' => t('The separator to use, including leading and trailing spaces'),
    '#default_value' => $this
      ->getSetting('separator_option'),
  );
  $element['element_option'] = array(
    '#type' => 'select',
    '#title' => t('Element'),
    '#description' => t('The HTML element to wrap each tag in'),
    '#default_value' => $this
      ->getSetting('element_option'),
    '#options' => array(
      '- None -' => '- None -',
      'span' => 'span',
      'h1' => 'h1',
      'h2' => 'h2',
      'h3' => 'h3',
      'h4' => 'h4',
      'h5' => 'h5',
      'strong' => 'h6',
      'em' => 'h7',
    ),
  );
  $element['element_class'] = array(
    '#type' => 'textfield',
    '#title' => t('Element Class'),
    '#description' => t('The class assigned to the element'),
    '#default_value' => $this
      ->getSetting('element_class'),
  );
  $element['wrapper_option'] = array(
    '#type' => 'select',
    '#title' => t('Wrapper'),
    '#description' => t('The HTML element to wrap the entire collection in'),
    '#default_value' => $this
      ->getSetting('wrapper_option'),
    '#options' => array(
      '- None -' => '- None -',
      'div' => 'div',
      'span' => 'span',
      'h1' => 'h1',
      'h2' => 'h2',
      'h3' => 'h3',
      'h4' => 'h4',
      'h5' => 'h5',
      'p' => 'p',
      'strong' => 'strong',
      'em' => 'em',
    ),
  );
  $element['wrapper_class'] = array(
    '#type' => 'textfield',
    '#title' => t('Wrapper Class'),
    '#description' => t('The class assigned to the wrapper'),
    '#default_value' => $this
      ->getSetting('wrapper_class'),
  );
  return $element;
}