You are here

public function FlotBlock::blockForm in Flot 8

Overrides BlockPluginTrait::blockForm

File

src/Plugin/Block/FlotBlock.php, line 47

Class

FlotBlock
Provides Flot Block.

Namespace

Drupal\flot\Plugin\Block

Code

public function blockForm($form, FormStateInterface $form_state) {

  //Selectbox for input type (JSON or Array)

  //TextBox for data input
  $config = $this
    ->getConfiguration();
  $data = isset($config['flot_block_settings']['data']) ? $config['flot_block_settings']['data'] : [];
  $text = "";
  $first = true;
  foreach ($data as $line) {
    if (!$first) {
      $text .= "\n";
    }
    else {
      $first = false;
    }
    $text .= $line;
  }
  $form['flot_block_type'] = [
    '#type' => 'select',
    '#title' => 'Chart Type',
    '#options' => [
      'Lines',
      'Bars',
      'Pie',
    ],
    '#default_value' => isset($config['flot_block_type']) ? $config['flot_block_type'] : 0,
  ];
  $form['flot_block_settings'] = [
    '#type' => 'textarea',
    '#title' => $this
      ->t('Flot Data'),
    '#default_value' => $text,
  ];
  return $form;
}