public function ChartsPluginStyleChart::validate in Charts 8
Same name and namespace in other branches
- 8.4 src/Plugin/views/style/ChartsPluginStyleChart.php \Drupal\charts\Plugin\views\style\ChartsPluginStyleChart::validate()
- 8.3 src/Plugin/views/style/ChartsPluginStyleChart.php \Drupal\charts\Plugin\views\style\ChartsPluginStyleChart::validate()
- 5.0.x src/Plugin/views/style/ChartsPluginStyleChart.php \Drupal\charts\Plugin\views\style\ChartsPluginStyleChart::validate()
Validate that the plugin is correct and can be saved.
Return value
An array of error strings to tell the user what is wrong with this plugin.
Overrides StylePluginBase::validate
File
- src/
Plugin/ views/ style/ ChartsPluginStyleChart.php, line 115
Class
- ChartsPluginStyleChart
- Style plugin to render view as a chart.
Namespace
Drupal\charts\Plugin\views\styleCode
public function validate() {
$errors = parent::validate();
$dataFields = $this->options['data_fields'];
$dataFieldsValueState = array();
$dataFieldsCounter = 0;
foreach ($dataFields as $value) {
/*if (count(array_unique($plugin)) === 1 && end($plugin) === 0) {
$errors[] = $this->t('At least one data field must be selected in the chart configuration before this chart may be shown');
}*/
/*Skip title field no need to validate it and if data field is set add to dataFieldsValueState array state 1
otherwise add to same array state 0*/
if ($dataFieldsCounter > 0) {
if (empty($value)) {
array_push($dataFieldsValueState, 0);
}
else {
array_push($dataFieldsValueState, 1);
}
}
$dataFieldsCounter++;
}
/*If total sum of dataFieldsValueState is less than 1, then no dataFields were selected otherwise 1 or more selected
total sum will be greater than 1*/
if (array_sum($dataFieldsValueState) < 1) {
$errors[] = $this
->t('At least one data field must be selected in the chart configuration before this chart may be shown');
}
return $errors;
}