You are here

public function EntityDefaultUIController::operationFormValidate in Entity API 7

Operation form validation callback.

File

includes/entity.ui.inc, line 392
Provides a controller for building an entity overview form.

Class

EntityDefaultUIController
Default UI controller providing admin UI.

Code

public function operationFormValidate($form, &$form_state) {
  if ($form_state['op'] == 'import') {
    if ($entity = entity_import($this->entityType, $form_state['values']['import'])) {

      // Store the successfully imported entity in $form_state.
      $form_state[$this->entityType] = $entity;
      if (!$form_state['values']['overwrite']) {

        // Check for existing entities with the same identifier.
        $id = entity_id($this->entityType, $entity);
        $entities = entity_load($this->entityType, array(
          $id,
        ));
        if (!empty($entities)) {
          $label = entity_label($this->entityType, $entity);
          $vars = array(
            '%entity' => $this->entityInfo['label'],
            '%label' => $label,
          );
          form_set_error('import', t('Import of %entity %label failed, a %entity with the same machine name already exists. Check the overwrite option to replace it.', $vars));
        }
      }
    }
    else {
      form_set_error('import', t('Import failed.'));
    }
  }
}