You are here

public function ChartsConfigForm::buildForm in Charts 8

Same name and namespace in other branches
  1. 8.4 src/Form/ChartsConfigForm.php \Drupal\charts\Form\ChartsConfigForm::buildForm()
  2. 8.3 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 38

Class

ChartsConfigForm

Namespace

Drupal\charts\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $config = $this->configFactory
    ->getEditable('charts.settings');
  $parents = array(
    'charts_default_settings',
  );
  $default_config = $config
    ->get('charts_default_settings');
  if ($default_config == NULL) {
    $defaults = [] + $this
      ->charts_default_settings();
  }
  else {
    $defaults = $default_config + $this
      ->charts_default_settings();
  }
  $field_options = array();
  $url = Url::fromRoute('views_ui.add');
  $link = Link::fromTextAndUrl($this
    ->t('create a new view'), $url)
    ->toRenderable();

  // Add help.
  $form['help'] = array(
    '#type' => 'markup',
    '#markup' => '<p>' . $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="!views">create a new view</a> and select
        the display format of "Chart".', array(
      '!views' => $link['url'],
    )) . '</p>',
    '#weight' => -100,
  );

  // Reuse the global settings form for defaults, but remove JS classes.
  $form = $this
    ->charts_settings_form($form, $defaults, $field_options, $parents);
  $form['xaxis']['#attributes']['class'] = array();
  $form['yaxis']['#attributes']['class'] = array();
  $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'] = array(
    '#type' => 'vertical_tabs',
  );

  // Add submit buttons and normal saving behavior.
  $form['actions']['#type'] = 'actions';
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => $this
      ->t('Save defaults'),
  );
  return $form;
}