You are here

public function OptionsForm::buildForm in Easychart 8.3

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form structure.

Overrides FormInterface::buildForm

File

src/Form/OptionsForm.php, line 27
Contains \Drupal\easychart\Form\OptionsForm

Class

OptionsForm

Namespace

Drupal\easychart\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, Request $request = NULL) {
  $form['#attached']['library'][] = 'easychart/easychart.admin';
  $form['#attached']['library'][] = 'easychart/lib.easycharts.full';
  $form['#attached']['library'][] = 'easychart/lib.highcharts';
  $default_options = '';
  if (file_exists('public://easychart-options.json')) {
    $default_options = file_get_contents('public://easychart-options.json');
  }
  $form['options'] = [
    '#type' => 'textarea',
    '#title' => $this
      ->t('Available options'),
    '#title_display' => 'invisible',
    '#description' => $this
      ->t('These Highcharts options will be configurable in the Easychart interface when creating/editing a chart. See <a href="@url" target="_blank">http://api.highcharts.com/highcharts</a> for all available options.', array(
      '@url' => Url::fromUri('http://api.highcharts.com/highcharts')
        ->toUriString(),
    )),
    '#default_value' => $default_options,
    '#attributes' => array(
      'class' => array(
        'easychart-options',
      ),
    ),
    '#rows' => 15,
  ];
  $form['actions']['submit'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Save configuration'),
    '#submit' => array(
      '::submitForm',
    ),
    '#button_type' => 'primary',
  ];
  $form['actions']['reset'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Reset to defaults'),
    '#submit' => array(
      '::resetForm',
    ),
    '#limit_validation_errors' => array(),
    '#weight' => 100,
  ];
  return $form;
}