You are here

public function Barcode::settingsForm in Barcodes 8

Same name and namespace in other branches
  1. 2.0.x src/Plugin/Field/FieldFormatter/Barcode.php \Drupal\barcodes\Plugin\Field\FieldFormatter\Barcode::settingsForm()

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/Barcode.php, line 52

Class

Barcode
Plugin implementation of the 'barcode' formatter.

Namespace

Drupal\barcodes\Plugin\Field\FieldFormatter

Code

public function settingsForm(array $form, FormStateInterface $form_state) {
  $generator = new BarcodeGenerator();
  $settings['type'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Barcode Type'),
    '#description' => $this
      ->t('The Barcode type.'),
    '#options' => array_combine($generator
      ->getTypes(), $generator
      ->getTypes()),
    '#default_value' => $this
      ->getSetting('type'),
  ];
  $settings['format'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Display Format'),
    '#description' => $this
      ->t('The display format, e.g. png, svg, jpg.'),
    '#options' => [
      'PNG' => 'PNG Image',
      'SVG' => 'SVG Image',
      'HTMLDIV' => 'HTML DIV',
      'UNICODE' => 'Unicode String',
      'BINARY' => 'Binary String',
    ],
    '#default_value' => $this
      ->getSetting('format'),
  ];
  $settings['color'] = [
    '#type' => 'color',
    '#title' => $this
      ->t('Color'),
    '#default_value' => $this
      ->getSetting('color'),
    '#description' => $this
      ->t('The color code.'),
  ];
  $settings['height'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Height'),
    '#size' => 10,
    '#default_value' => $this
      ->getSetting('height'),
    '#description' => $this
      ->t('The height in pixels.'),
  ];
  $settings['width'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Width'),
    '#size' => 10,
    '#default_value' => $this
      ->getSetting('width'),
    '#description' => $this
      ->t('The width in pixels'),
  ];
  $settings['padding_top'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Padding-Top'),
    '#size' => 4,
    '#maxlength' => 4,
    '#default_value' => $this
      ->getSetting('padding_top'),
    '#description' => $this
      ->t('The top padding in pixels'),
  ];
  $settings['padding_right'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Padding-Right'),
    '#size' => 4,
    '#maxlength' => 4,
    '#default_value' => $this
      ->getSetting('padding_right'),
    '#description' => $this
      ->t('The right padding in pixels'),
  ];
  $settings['padding_bottom'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Padding-Bottom'),
    '#size' => 4,
    '#maxlength' => 4,
    '#default_value' => $this
      ->getSetting('padding_bottom'),
    '#description' => $this
      ->t('The bottom padding in pixels'),
  ];
  $settings['padding_left'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Padding-Left'),
    '#size' => 4,
    '#maxlength' => 4,
    '#default_value' => $this
      ->getSetting('padding_left'),
    '#description' => $this
      ->t('The left padding in pixels'),
  ];
  $settings['show_value'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Show value'),
    '#default_value' => $this
      ->getSetting('show_value'),
    '#description' => $this
      ->t('Show the actual value in addition to the barcode'),
  ];
  return $settings + parent::settingsForm($form, $form_state);
}