public function EntityTestFormController::save

Overrides Drupal\Core\Entity\EntityFormController::save().

Overrides EntityFormController::save

File

drupal/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/EntityTestFormController.php, line 85
Definition of Drupal\entity_test\EntityTestFormController.

Class

EntityTestFormController
Form controller for the test entity edit forms.

Namespace

Drupal\entity_test

Code

public function save(array $form, array &$form_state) {
  $entity = $this->entity;
  $is_new = $entity
    ->isNew();
  $entity
    ->save();
  if ($is_new) {
    $message = t('%entity_type @id has been created.', array(
      '@id' => $entity
        ->id(),
      '%entity_type' => $entity
        ->entityType(),
    ));
  }
  else {
    $message = t('%entity_type @id has been updated.', array(
      '@id' => $entity
        ->id(),
      '%entity_type' => $entity
        ->entityType(),
    ));
  }
  drupal_set_message($message);
  if ($entity
    ->id()) {
    $form_state['redirect'] = $entity
      ->entityType() . '/manage/' . $entity
      ->id() . '/edit';
  }
  else {

    // Error on save.
    drupal_set_message(t('The entity could not be saved.'), 'error');
    $form_state['rebuild'] = TRUE;
  }
}