You are here

public function ChartsConfigForm::buildForm in Charts 8.3

Same name in this branch
  1. 8.3 src/Form/ChartsConfigForm.php \Drupal\charts\Form\ChartsConfigForm::buildForm()
  2. 8.3 modules/charts_chartjs/src/Form/ChartsConfigForm.php \Drupal\charts_chartjs\Form\ChartsConfigForm::buildForm()
  3. 8.3 modules/charts_google/src/Form/ChartsConfigForm.php \Drupal\charts_google\Form\ChartsConfigForm::buildForm()
  4. 8.3 modules/charts_billboard/src/Form/ChartsConfigForm.php \Drupal\charts_billboard\Form\ChartsConfigForm::buildForm()
  5. 8.3 modules/charts_c3/src/Form/ChartsConfigForm.php \Drupal\charts_c3\Form\ChartsConfigForm::buildForm()
  6. 8.3 modules/charts_highcharts/src/Form/ChartsConfigForm.php \Drupal\charts_highcharts\Form\ChartsConfigForm::buildForm()
Same name and namespace in other branches
  1. 8.4 src/Form/ChartsConfigForm.php \Drupal\charts\Form\ChartsConfigForm::buildForm()
  2. 8 src/Form/ChartsConfigForm.php \Drupal\charts\Form\ChartsConfigForm::buildForm()
  3. 5.0.x src/Form/ChartsConfigForm.php \Drupal\charts\Form\ChartsConfigForm::buildForm()

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

File

src/Form/ChartsConfigForm.php, line 54

Class

ChartsConfigForm
Charts Config Form.

Namespace

Drupal\charts\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $parents = [
    'charts_default_settings',
  ];
  $default_config = $this->config
    ->get('charts_default_settings');
  if (!isset($default_config)) {
    $defaultSettings = new ChartsDefaultSettings();
    $default_config = $defaultSettings
      ->getDefaults();
  }
  $defaults = array_merge($this->defaults
    ->getDefaults(), $default_config);
  $field_options = [];
  $form['help'] = [
    '#type' => 'markup',
    '#prefix' => '<p>',
    '#suffix' => '</p>',
    '#markup' => $this
      ->t('The settings on this page are used to set
        <strong>default</strong> settings. They do not affect existing charts.
        To make a new chart, <a href="@create">create a new view</a> and select
        the display format of "Chart".', [
      '@create' => Url::fromRoute('views_ui.add')
        ->toString(),
    ]),
    '#weight' => -100,
  ];

  // Reuse the global settings form for defaults, but remove JS classes.
  $form = $this->chartsBaseSettingsForm
    ->getChartsBaseSettingsForm($form, $defaults, $field_options, $parents, 'config_form');
  $form['xaxis']['#attributes']['class'] = [];
  $form['yaxis']['#attributes']['class'] = [];
  $form['display']['colors']['#prefix'] = NULL;
  $form['display']['colors']['#suffix'] = NULL;

  // Put settings into vertical tabs.
  $form['display']['#group'] = 'defaults';
  $form['xaxis']['#group'] = 'defaults';
  $form['yaxis']['#group'] = 'defaults';
  $form['defaults'] = [
    '#type' => 'vertical_tabs',
  ];
  return parent::buildForm($form, $form_state);
}