You are here

public function CloneEntityType::validateForm in Entity Type Clone 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/CloneEntityType.php, line 160

Class

CloneEntityType
Class CloneEntityType.

Namespace

Drupal\entity_type_clone\Form

Code

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

  // Get the form state values.
  $values = $form_state
    ->getValues();
  $entity_type = $values['show']['entity_type'];

  // Get the existing entity type machine names.
  $entityTypesNames = $this
    ->getMachineNamesof($entity_type);
  if ($entityTypesNames && in_array($values['clone_bundle_machine'], $entityTypesNames)) {
    $form_state
      ->setErrorByName('clone_bundle_machine', $this
      ->t('The machine name of the target entity type already exists.'));
  }
}