class EntityTestFormController

Form controller for the test entity edit forms.

Hierarchy

Expanded class hierarchy of EntityTestFormController

File

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

Namespace

Drupal\entity_test
View source
class EntityTestFormController extends EntityFormControllerNG {

  /**
   * Overrides Drupal\Core\Entity\EntityFormController::form().
   */
  public function form(array $form, array &$form_state, EntityInterface $entity) {
    $form = parent::form($form, $form_state, $entity);
    $langcode = $this
      ->getFormLangcode($form_state);
    $translation = $entity
      ->getTranslation($langcode);
    $form['name'] = array(
      '#type' => 'textfield',
      '#title' => t('Name'),
      '#default_value' => $translation->name->value,
      '#size' => 60,
      '#maxlength' => 128,
      '#required' => TRUE,
      '#weight' => -10,
    );
    $form['user_id'] = array(
      '#type' => 'textfield',
      '#title' => 'UID',
      '#default_value' => $translation->user_id->value,
      '#size' => 60,
      '#maxlength' => 128,
      '#required' => TRUE,
      '#weight' => -10,
    );
    $form['langcode'] = array(
      '#title' => t('Language'),
      '#type' => 'language_select',
      '#default_value' => $entity
        ->language()->langcode,
      '#languages' => LANGUAGE_ALL,
    );
    return $form;
  }

  /**
   * Overrides Drupal\Core\Entity\EntityFormController::save().
   */
  public function save(array $form, array &$form_state) {
    $entity = $this
      ->getEntity($form_state);
    $is_new = $entity
      ->isNew();
    $entity
      ->save();
    $message = $is_new ? t('entity_test @id has been created.', array(
      '@id' => $entity
        ->id(),
    )) : t('entity_test @id has been updated.', array(
      '@id' => $entity
        ->id(),
    ));
    drupal_set_message($message);
    if ($entity
      ->id()) {
      $form_state['redirect'] = 'entity-test/manage/' . $entity
        ->id() . '/edit';
    }
    else {

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

  /**
   * Overrides Drupal\Core\Entity\EntityFormController::delete().
   */
  public function delete(array $form, array &$form_state) {
    $entity = $this
      ->getEntity($form_state);
    $entity
      ->delete();
    drupal_set_message(t('entity_test @id has been deleted.', array(
      '@id' => $entity
        ->id(),
    )));
    $form_state['redirect'] = '<front>';
  }

}

Members

Namesort descending Modifiers Type Description Overrides
EntityFormController::$operation protected property The name of the current operation.
EntityFormController::actions protected function Returns an array of supported actions for the current entity form. 10
EntityFormController::actionsElement protected function Returns the action form element for the current entity form. 1
EntityFormController::build public function Implements Drupal\Core\Entity\EntityFormControllerInterface::build(). Overrides EntityFormControllerInterface::build
EntityFormController::getEntity public function Implements Drupal\Core\Entity\EntityFormControllerInterface::getEntity(). Overrides EntityFormControllerInterface::getEntity 1
EntityFormController::getFormLangcode public function Implements Drupal\Core\Entity\EntityFormControllerInterface::getFormLangcode(). Overrides EntityFormControllerInterface::getFormLangcode
EntityFormController::getOperation public function Implements Drupal\Core\Entity\EntityFormControllerInterface::getOperation(). Overrides EntityFormControllerInterface::getOperation
EntityFormController::init protected function Initialize the form state and the entity before the first form build.
EntityFormController::isDefaultFormLangcode public function Implements EntityFormControllerInterface::isDefaultFormLangcode(). Overrides EntityFormControllerInterface::isDefaultFormLangcode
EntityFormController::prepareEntity protected function Prepares the entity object before the form is built first. 2
EntityFormController::setEntity public function Implements Drupal\Core\Entity\EntityFormControllerInterface::setEntity(). Overrides EntityFormControllerInterface::setEntity 1
EntityFormController::submit public function Implements Drupal\Core\Entity\EntityFormControllerInterface::submit(). Overrides EntityFormControllerInterface::submit 9
EntityFormController::submitEntityLanguage protected function Handle possible entity language changes.
EntityFormController::__construct public function Constructs an EntityFormController object.
EntityFormControllerNG::buildEntity public function Overrides EntityFormController::buildEntity(). Overrides EntityFormController::buildEntity
EntityFormControllerNG::validate public function Overrides EntityFormController::validate(). Overrides EntityFormController::validate
EntityTestFormController::delete public function Overrides Drupal\Core\Entity\EntityFormController::delete(). Overrides EntityFormController::delete
EntityTestFormController::form public function Overrides Drupal\Core\Entity\EntityFormController::form(). Overrides EntityFormControllerNG::form
EntityTestFormController::save public function Overrides Drupal\Core\Entity\EntityFormController::save(). Overrides EntityFormController::save