You are here

public function ChartsPluginStyleChart::buildOptionsForm in Charts 8

Same name and namespace in other branches
  1. 8.4 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 58

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'] = array(
      '#markup' => '<div class="error messages">' . t('You need at least one field before you can configure your table settings') . '</div>',
    );
  }

  // Limit grouping options (we only support one grouping field).
  if (isset($form['grouping'][0])) {
    $form['grouping'][0]['field']['#title'] = t('Grouping field');
    $form['grouping'][0]['field']['#description'] = t('If grouping by a particular field, that field will be used to generate multiple data series on the same chart.');
    $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 = charts_settings_form($form, $this->options, $field_options, array(
    'style_options',
  ));

  // Reduce the options if this is a chart extension.

  /*if (empty($this->displayHandler->getAttachedDisplays())) {
      $form['type']['#description'] = empty($form['type']['#description']) ? '' : $form['type']['#description'] . ' ';
      $form['type']['#description'] .= t('This chart will be combined with the parent display "@display_title",
          which is a "@type" chart. Not all chart types may be combined. Selecting a different chart type than
          the parent may cause errors.' //,
      //    array('@display_title' => $parent_display->display_title, '@type' => $parent_chart_type['label'])
      );
      $form['fields']['label_field']['#disabled'] = TRUE;
      $form['display']['#access'] = FALSE;
      $form['xaxis']['#access'] = FALSE;
      if ($this->displayHandler->options['inherit_yaxis']) {
        $form['yaxis']['#access'] = FALSE;
      }
      else {
        $form['yaxis']['#title'] = t('Secondary axis');
        $form['yaxis']['#attributes']['class'] = array();
      }
    }*/
}