You are here

public function WebformAnalysisForm::buildForm in Webform Analysis 8

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 EntityForm::buildForm

File

src/Form/WebformAnalysisForm.php, line 38

Class

WebformAnalysisForm
Webform Analysis settings form.

Namespace

Drupal\webform_analysis\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $this->analysis = new WebformAnalysis($this->entity);
  $form['#title'] = $this
    ->getTitle();
  if (!$this->analysis
    ->getWebform()) {
    return $form;
  }
  $chart = new WebformAnalysisChart($this->entity, $this->analysis
    ->getComponents(), $this->analysis
    ->getChartType());
  $chart
    ->build($form);
  $form['components_settings'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Add analysis components'),
    '#open' => FALSE,
    'analysis_components' => $this
      ->getComponents(),
  ];
  $form['analysis_chart_type'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Charts type'),
    '#default_value' => $this->analysis
      ->getChartType(),
    '#options' => WebformAnalysis::getChartTypeOptions(),
  ];
  $form['actions']['#type'] = 'actions';
  $form['actions']['submit'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Update analysis display'),
    '#button_type' => 'primary',
    '#submit' => [
      '::submitForm',
      '::save',
    ],
  ];
  $form['#attached']['library'][] = 'webform_analysis/webform_analysis';
  return $form;
}