public function Visualization::buildOptionsForm in Visualization API 8
Returns the options form.
Overrides StylePluginBase::buildOptionsForm
File
- src/
Plugin/ views/ style/ Visualization.php, line 79 - Definition of Drupal\visualization\Plugin\views\style\Visualization.
Class
- Visualization
- Style plugin uses views ui to configure views data for rendering charts.
Namespace
Drupal\visualization\Plugin\views\styleCode
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
parent::buildOptionsForm($form, $form_state);
$handlers = $this->displayHandler
->getHandlers('field');
$fields = $this->displayHandler
->getFieldLabels();
$form['type'] = array(
'#type' => 'select',
'#title' => t('Chart type'),
'#options' => array(
'line' => 'Line chart',
'pie' => 'Pie chart',
'bar' => 'Bar chart',
'column' => 'Column chart',
),
'#default_value' => $this->options['type'],
'#empty_value' => FALSE,
);
$form['fields'] = array(
'#type' => 'fieldset',
'#title' => t('Field settings'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
foreach ($fields as $field => $column) {
$handler = $handlers[$field];
$form['fields'][$field] = array(
'#type' => 'details',
'#title' => SafeMarkup::checkPlain($field),
'#collapsible' => TRUE,
'#collapsed' => empty($this->options['fields'][$field]),
);
$form['fields'][$field]['enabled'] = array(
'#type' => 'checkbox',
'#title' => t('Enable this field in the chart'),
'#default_value' => empty($this->options['fields'][$field]['enabled']) ? FALSE : $this->options['fields'][$field]['enabled'],
'#dependency' => array(
'style_options',
'fields',
$field,
'type',
),
);
if ($handler
->clickSortable()) {
$form['fields'][$field]['sort'] = array(
'#type' => 'select',
'#title' => t('Sort'),
'#options' => array(
'DESC' => t('Descending'),
'ASC' => t('Ascending'),
),
'#default_value' => empty($this->options['fields'][$field]['sort']) ? FALSE : $this->options['fields'][$field]['sort'],
'#empty_value' => FALSE,
);
}
}
$form['xAxis'] = array(
'#type' => 'fieldset',
'#title' => t('X-axis settings'),
'#collapsible' => TRUE,
'#collapsed' => !empty($this->options['xAxis']['labelField']) || !empty($this->options['xAxis']['invert']),
);
$form['xAxis']['labelField'] = array(
'#type' => 'select',
'#title' => t('X-axis labels'),
'#options' => $fields,
'#default_value' => $this->options['xAxis']['labelField'],
'#empty_value' => FALSE,
);
$form['xAxis']['invert'] = array(
'#type' => 'checkbox',
'#title' => t('Should the x-axis get inverted?'),
'#default_value' => $this->options['xAxis']['invert'],
);
$form['yAxis'] = array(
'#type' => 'fieldset',
'#title' => t('Y-axis settings'),
'#collapsible' => TRUE,
'#collapsed' => empty($this->options['yAxis']['title']),
);
$form['yAxis']['title'] = array(
'#type' => 'textfield',
'#title' => t('Y-axis title'),
'#default_value' => $this->options['yAxis']['title'],
);
}