You are here

public function CustomPublishingOptionForm::validateForm in Custom Publishing Options 8

Form validation handler.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Overrides FormBase::validateForm

File

src/Form/CustomPublishingOptionForm.php, line 95

Class

CustomPublishingOptionForm
Class CustomPublishingOptionForm.

Namespace

Drupal\custom_pub\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {

  // check to see if a field definition exists by this machine name to prevent collisions/overwrites
  $entity = $this->entity;
  $storage_definition = $this->entityDefinitionManager
    ->getFieldStorageDefinition($entity
    ->id(), 'node');
  if ($entity
    ->isNew() && isset($storage_definition)) {
    $form_state
      ->setError($form['id'], $this
      ->t('Cannot use machine name %name - field definition already exists.', [
      '%name' => $entity
        ->id(),
    ]));
  }
}