function ContextConfigure::validateForm

Same name and namespace in other branches
  1. 4.0.x src/Form/ContextConfigure.php \Drupal\ctools\Form\ContextConfigure::validateForm()

Overrides FormBase::validateForm

File

src/Form/ContextConfigure.php, line 171

Class

ContextConfigure
Configure Context Form.

Namespace

Drupal\ctools\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  // If these are not equal, then we're adding a new context and should not override an existing context.
  if ($form_state->getValue('machine_name') != $form_state->getValue('context_id')) {
    $machine_name = $form_state->getValue('machine_name');
    $cached_values = $this->tempstore
      ->get($this->tempstore_id)
      ->get($this->machine_name);
    if (!empty($this->getContexts($cached_values)[$machine_name])) {
      $form_state->setError($form['machine_name'], $this->t('That machine name is in use by another context definition.'));
    }
  }
}