You are here

public function ViewsConditionalField::validateOptionsForm in Views Conditional 8

Validate the options form.

Overrides PluginBase::validateOptionsForm

File

src/Plugin/views/field/ViewsConditionalField.php, line 202

Class

ViewsConditionalField
Field handler to flag the node type.

Namespace

Drupal\views_conditional\Plugin\views\field

Code

public function validateOptionsForm(&$form, FormStateInterface $form_state) {
  $values = $form_state
    ->getValues();
  if (empty($values['options']['if']) || empty($values['options']['condition']) || empty($values['options']['equalto'])) {
    if (empty($values['options']['if'])) {
      $form_state
        ->setErrorByName('if', $this
        ->t("Please specify a valid field to run a condition on."));
    }
    if (empty($values['options']['condition'])) {
      $form_state
        ->setErrorByName('condition', $this
        ->t("Please select a conditional operator."));
    }

    // We using there is_numeric because values '0', '0.0' counts as empty.
    if (empty($values['options']['equalto']) && !in_array($values['options']['condition'], [
      'em',
      'nem',
    ]) && !is_numeric($values['options']['equalto'])) {
      $form_state
        ->setErrorByName('condition', $this
        ->t("Please specify something to compare with."));
    }
  }
}