You are here

public function EntityUpdateExec::submitFormSafe in Entity Update 8

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

Run updates using safe (full) method.

File

src/Form/EntityUpdateExec.php, line 230

Class

EntityUpdateExec
Class CheckEntityUpdate.

Namespace

Drupal\entity_update\Form

Code

public function submitFormSafe(array &$form, FormStateInterface $form_state) {
  try {
    $type = $form_state
      ->getValue('entity_type_id');
    $entity_type = entity_update_get_entity_type($type);

    // Update the entity type.
    $res = EntityUpdate::safeUpdateMain($entity_type);
    $res_str = $res ? 'SUCCESS' : 'FAIL';
    $status = $res ? 'status' : 'error';
    $options = [
      '@res' => $res_str,
      '@type' => $entity_type
        ->getLabel(),
    ];
    drupal_set_message($this
      ->t("Entity @type update @res", $options), $status);
  } catch (\Exception $e) {
    drupal_set_message($this
      ->t("Entity update Fail"), 'error');
    drupal_set_message($e
      ->getMessage(), 'error');
  }
}