You are here

public function Barcode::blockForm in Barcodes 2.0.x

Same name and namespace in other branches
  1. 8 src/Plugin/Block/Barcode.php \Drupal\barcodes\Plugin\Block\Barcode::blockForm()

Overrides BlockPluginTrait::blockForm

File

src/Plugin/Block/Barcode.php, line 134

Class

Barcode
Provides a 'Barcode' block.

Namespace

Drupal\barcodes\Plugin\Block

Code

public function blockForm($form, FormStateInterface $form_state) {
  $generator = new BarcodeGenerator();
  $form['value'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Value'),
    '#description' => $this
      ->t('The Barcode value.'),
    '#default_value' => $this->configuration['value'],
  ];
  if ($this->moduleHandler
    ->moduleExists('token')) {
    $form['value'] += [
      '#element_validate' => [
        'token_element_validate',
      ],
      '#token_types' => [
        'node',
      ],
    ];
    $form['token_help'] = [
      '#theme' => 'token_tree_link',
      '#token_types' => [
        'node',
      ],
    ];
  }
  $form['type'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Barcode Type'),
    '#description' => $this
      ->t('The Barcode type.'),
    '#options' => array_combine($generator
      ->getTypes(), $generator
      ->getTypes()),
    '#default_value' => $this->configuration['type'],
  ];
  $form['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->configuration['format'],
  ];
  $form['color'] = [
    '#type' => 'color',
    '#title' => $this
      ->t('Color'),
    '#default_value' => $this->configuration['color'],
    '#description' => $this
      ->t('The color code.'),
  ];
  $form['height'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Height'),
    '#size' => 10,
    '#default_value' => $this->configuration['height'],
    '#description' => $this
      ->t('The height in pixels.'),
  ];
  $form['width'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Width'),
    '#size' => 10,
    '#default_value' => $this->configuration['width'],
    '#description' => $this
      ->t('The width in pixels'),
  ];
  $form['padding_top'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Padding-Top'),
    '#size' => 4,
    '#maxlength' => 4,
    '#default_value' => $this->configuration['padding_top'],
    '#description' => $this
      ->t('The top padding in pixels'),
  ];
  $form['padding_right'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Padding-Right'),
    '#size' => 4,
    '#maxlength' => 4,
    '#default_value' => $this->configuration['padding_right'],
    '#description' => $this
      ->t('The right padding in pixels'),
  ];
  $form['padding_bottom'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Padding-Bottom'),
    '#size' => 4,
    '#maxlength' => 4,
    '#default_value' => $this->configuration['padding_bottom'],
    '#description' => $this
      ->t('The bottom padding in pixels'),
  ];
  $form['padding_left'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Padding-Left'),
    '#size' => 4,
    '#maxlength' => 4,
    '#default_value' => $this->configuration['padding_left'],
    '#description' => $this
      ->t('The left padding in pixels'),
  ];
  $form['show_value'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Show value'),
    '#default_value' => $this->configuration['show_value'],
    '#description' => $this
      ->t('Show the actual value in addition to the barcode'),
  ];
  return $form;
}