You are here

public function ChartsPluginStyleChart::buildOptionsForm in Charts 8.4

Same name and namespace in other branches
  1. 8 src/Plugin/views/style/ChartsPluginStyleChart.php \Drupal\charts\Plugin\views\style\ChartsPluginStyleChart::buildOptionsForm()
  2. 8.3 src/Plugin/views/style/ChartsPluginStyleChart.php \Drupal\charts\Plugin\views\style\ChartsPluginStyleChart::buildOptionsForm()
  3. 5.0.x src/Plugin/views/style/ChartsPluginStyleChart.php \Drupal\charts\Plugin\views\style\ChartsPluginStyleChart::buildOptionsForm()

Provide a form to edit options for this plugin.

Overrides StylePluginBase::buildOptionsForm

File

src/Plugin/views/style/ChartsPluginStyleChart.php, line 151

Class

ChartsPluginStyleChart
Style plugin to render view as a chart.

Namespace

Drupal\charts\Plugin\views\style

Code

public function buildOptionsForm(&$form, FormStateInterface $form_state) {
  parent::buildOptionsForm($form, $form_state);
  $handlers = $this->displayHandler
    ->getHandlers('field');
  if (empty($handlers)) {
    $form['error_markup'] = [
      '#markup' => '<div class="error messages">' . $this
        ->t('You need at least one field before you can configure your table settings') . '</div>',
    ];
    return;
  }

  // Limit grouping options (we only support one grouping field).
  if (isset($form['grouping'][0])) {
    $form['grouping'][0]['field']['#title'] = $this
      ->t('Grouping field');
    $form['grouping'][0]['field']['#description'] = $this
      ->t('If grouping by a particular field, that field will be used to determine stacking of the chart. Generally this will be the same field as what you select for the "Label field" below. If you do not have more than one "Provides data" field below, there will be nothing to stack. If you want to have another series displayed, use a "Chart attachment" display, and set it to attach to this display.');
    $form['grouping'][0]['field']['#attributes']['class'][] = 'charts-grouping-field';

    // Grouping by rendered version has no effect in charts. Hide the options.
    $form['grouping'][0]['rendered']['#access'] = FALSE;
    $form['grouping'][0]['rendered_strip']['#access'] = FALSE;
  }
  if (isset($form['grouping'][1])) {
    $form['grouping'][1]['#access'] = FALSE;
  }

  // Merge in the global chart settings form.
  $field_options = $this->displayHandler
    ->getFieldLabels();
  $form_state
    ->set('default_options', $this->options);
  $form['chart_settings'] = [
    '#type' => 'charts_settings',
    '#used_in' => 'view_form',
    '#required' => TRUE,
    '#field_options' => $field_options,
    '#default_value' => $this->options['chart_settings'],
  ];
}