You are here

public function EntityUpdateExec::validateSafe in Entity Update 2.0.x

Same name and namespace in other branches
  1. 8 src/Form/EntityUpdateExec.php \Drupal\entity_update\Form\EntityUpdateExec::validateSafe()

Safe mode validation.

File

src/Form/EntityUpdateExec.php, line 176

Class

EntityUpdateExec
Class CheckEntityUpdate.

Namespace

Drupal\entity_update\Form

Code

public function validateSafe(array &$form, FormStateInterface $form_state) {
  $type = $form_state
    ->getValue('entity_type_id');
  $list = EntityUpdate::getEntityTypesToUpdate($type);
  if (!isset($list[$type])) {
    $form_state
      ->setErrorByName('entity_type_id', $this
      ->t("No updates for entity_type_id"));
    return;
  }
  $entity_type_changes = $list[$type];

  // Init flags.
  $flg_has_install = FALSE;
  $flg_has_uninstall = FALSE;

  // Check install/uninstall.
  foreach ($entity_type_changes as $entity_change_summ) {
    if (strstr($entity_change_summ, "uninstalled")) {
      $flg_has_uninstall = TRUE;
    }
    else {
      $flg_has_install = TRUE;
    }
  }

  // Check and print instruction.
  if ($flg_has_install && $flg_has_uninstall) {
    $form_state
      ->setErrorByName('entity_type_id', $this
      ->t("Multiple actions detected, cant update if contains data. Use basic method."));
    return;
  }
}