public function ExcelExport::validateOptionsForm in Excel Serialization 8
Validate the options form.
Overrides PathPluginBase::validateOptionsForm
File
- src/
Plugin/ views/ display/ ExcelExport.php, line 280
Class
- ExcelExport
- Provides an Excel export display plugin.
Namespace
Drupal\xls_serialization\Plugin\views\displayCode
public function validateOptionsForm(&$form, FormStateInterface $form_state) {
parent::validateOptionsForm($form, $form_state);
// Validate Excel sheet header formatting functionality fields.
if ($form_state
->get('section') == 'format_header') {
$errors = $this
->validateRgbValue($form_state
->getValue('header_background_color'));
foreach ($errors as $error) {
$form_state
->setError($form['header_background_color'], $error);
}
}
// Validate Excel conditional formatting functionality fields.
for ($i = 0; $i <= 4; $i++) {
if ($form_state
->get('section') === 'excel_conditional_formatting_rules_' . $i) {
// If one of conditional_formatting_base_field,
// conditional_formatting_operator or conditional_formatting_compare_to
// is set, all of them have to be set.
$conditional_formatting_base_field_value[$i] = $form_state
->getValue('conditional_formatting_base_field_' . $i);
$conditional_formatting_operator_value[$i] = $form_state
->getValue('conditional_formatting_operator_' . $i);
$conditional_formatting_compare_to_value[$i] = $form_state
->getValue('conditional_formatting_compare_to_' . $i);
if ($conditional_formatting_base_field_value[$i] !== 'Select a field') {
if ($conditional_formatting_operator_value[$i] === 'Select an operator' || $conditional_formatting_compare_to_value[$i] === '') {
$form_state
->setError($form['conditional_formatting_base_field'], $this
->t('Either all or none of the following three inputs must be set: "Field used to compare to text", "Operator" and "Text to compare to".'));
}
}
if ($conditional_formatting_operator_value[$i] !== 'Select an operator') {
if ($conditional_formatting_base_field_value[$i] === 'Select a field' || $conditional_formatting_compare_to_value[$i] === '') {
$form_state
->setError($form['conditional_formatting_operator'], $this
->t('Either all or none of the following three inputs must be set: "Field used to compare to text", "Operator" and "Text to compare to".'));
}
}
if ($conditional_formatting_compare_to_value[$i] !== '') {
if ($conditional_formatting_base_field_value[$i] === 'Select a field' || $conditional_formatting_operator_value[$i] === 'Select an operator') {
$form_state
->setError($form['conditional_formatting_compare_to'], $this
->t('Either all or none of the following three inputs must be set: "Field used to compare to text", "Operator" and "Text to compare to".'));
}
}
$form_state
->setValue('conditional_formatting_background_color_' . $i, strtoupper($form_state
->getValue('conditional_formatting_background_color_' . $i)));
$errors = $this
->validateRgbValue($form_state
->getValue('conditional_formatting_background_color_' . $i));
foreach ($errors as $error) {
$form_state
->setError($form['conditional_formatting_background_color_' . $i], $error);
}
}
}
// Uppercase the background color RGB values.
$form_state
->setValue('header_background_color', strtoupper($form_state
->getValue('header_background_color')));
}