class EntityFormControllerNG

Entity form controller variant for entity types using the new property API.

@todo: Merge with EntityFormController and overhaul once all entity types are converted to the new entity field API.

See the EntityNG documentation for an explanation of "NG".

Hierarchy

Expanded class hierarchy of EntityFormControllerNG

See also

\Drupal\Core\EntityNG

5 files declare their use of EntityFormControllerNG
CommentFormController.php in drupal/core/modules/comment/lib/Drupal/comment/CommentFormController.php
Definition of Drupal\comment\CommentFormController.
CustomBlockFormController.php in drupal/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockFormController.php
Contains \Drupal\custom_block\CustomBlockFormController.
EntityTestFormController.php in drupal/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/EntityTestFormController.php
Definition of Drupal\entity_test\EntityTestFormController.
FeedFormController.php in drupal/core/modules/aggregator/lib/Drupal/aggregator/FeedFormController.php
Contains \Drupal\aggregator\FeedFormController.
TermFormController.php in drupal/core/modules/taxonomy/lib/Drupal/taxonomy/TermFormController.php
Definition of Drupal\taxonomy\TermFormController.

File

drupal/core/lib/Drupal/Core/Entity/EntityFormControllerNG.php, line 20
Contains \Drupal\Core\Entity\EntityFormControllerNG.

Namespace

Drupal\Core\Entity
View source
class EntityFormControllerNG extends EntityFormController {

  /**
   * Overrides EntityFormController::form().
   */
  public function form(array $form, array &$form_state) {
    $entity = $this->entity;

    // @todo Exploit the Field API to generate the default widgets for the
    // entity fields.
    $info = $entity
      ->entityInfo();
    if (!empty($info['fieldable'])) {
      field_attach_form($entity, $form, $form_state, $this
        ->getFormLangcode($form_state));
    }

    // Assign the weights configured in the form display.
    foreach ($this
      ->getFormDisplay($form_state)
      ->getComponents() as $name => $options) {
      if (isset($form[$name])) {
        $form[$name]['#weight'] = $options['weight'];
      }
    }
    return $form;
  }

  /**
   * Overrides EntityFormController::validate().
   */
  public function validate(array $form, array &$form_state) {

    // @todo Exploit the Field API to validate the values submitted for the
    // entity fields.
    $entity = $this
      ->buildEntity($form, $form_state);
    $info = $entity
      ->entityInfo();
    if (!empty($info['fieldable'])) {
      field_attach_form_validate($entity, $form, $form_state);
    }

    // @todo Remove this.
    // Execute legacy global validation handlers.
    unset($form_state['validate_handlers']);
    form_execute_handlers('validate', $form, $form_state);
  }

  /**
   * Overrides EntityFormController::submitEntityLanguage().
   */
  protected function submitEntityLanguage(array $form, array &$form_state) {

    // Nothing to do here, as original field values are always stored with
    // Language::LANGCODE_DEFAULT language.
    // @todo Delete this method when merging EntityFormControllerNG with
    //   EntityFormController.
  }

  /**
   * Overrides EntityFormController::buildEntity().
   */
  public function buildEntity(array $form, array &$form_state) {
    $entity = clone $this->entity;
    $entity_type = $entity
      ->entityType();
    $info = entity_get_info($entity_type);

    // @todo Exploit the Field API to process the submitted entity fields.
    // Copy top-level form values that are entity fields but not handled by
    // field API without changing existing entity fields that are not being
    // edited by this form. Values of fields handled by field API are copied
    // by field_attach_extract_form_values() below.
    $values_excluding_fields = $info['fieldable'] ? array_diff_key($form_state['values'], field_info_instances($entity_type, $entity
      ->bundle())) : $form_state['values'];
    $translation = $entity
      ->getTranslation($this
      ->getFormLangcode($form_state), FALSE);
    $definitions = $translation
      ->getPropertyDefinitions();
    foreach ($values_excluding_fields as $key => $value) {
      if (isset($definitions[$key])) {
        $translation->{$key} = $value;
      }
    }

    // Invoke all specified builders for copying form values to entity fields.
    if (isset($form['#entity_builders'])) {
      foreach ($form['#entity_builders'] as $function) {
        call_user_func_array($function, array(
          $entity_type,
          $entity,
          &$form,
          &$form_state,
        ));
      }
    }

    // Invoke field API for copying field values.
    if ($info['fieldable']) {
      field_attach_extract_form_values($entity, $form, $form_state);
    }
    return $entity;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
EntityFormController::$entity protected property The entity being used by this form.
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. 17
EntityFormController::actionsElement protected function Returns the action form element for the current entity form.
EntityFormController::buildForm public function Form constructor. Overrides FormInterface::buildForm 1
EntityFormController::delete public function Form submission handler for the 'delete' action. 12
EntityFormController::getBaseFormID public function Returns a string identifying the base form. Overrides BaseFormIdInterface::getBaseFormID
EntityFormController::getEntity public function Implements \Drupal\Core\Entity\EntityFormControllerInterface::getEntity(). Overrides EntityFormControllerInterface::getEntity
EntityFormController::getFormDisplay public function Returns the form display. Overrides EntityFormControllerInterface::getFormDisplay
EntityFormController::getFormID public function Returns a unique string identifying the form. Overrides FormInterface::getFormID
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. 1
EntityFormController::isDefaultFormLangcode public function Implements \Drupal\Core\Entity\EntityFormControllerInterface::isDefaultFormLangcode(). Overrides EntityFormControllerInterface::isDefaultFormLangcode
EntityFormController::prepareEntity protected function Prepares the entity object before the form is built first. 3
EntityFormController::save public function Form submission handler for the 'save' action. 20
EntityFormController::setEntity public function Implements \Drupal\Core\Entity\EntityFormControllerInterface::setEntity(). Overrides EntityFormControllerInterface::setEntity
EntityFormController::setFormDisplay public function Sets the form display. Overrides EntityFormControllerInterface::setFormDisplay
EntityFormController::setOperation public function Sets the operation for this form.
EntityFormController::submit public function Implements \Drupal\Core\Entity\EntityFormControllerInterface::submit(). Overrides EntityFormControllerInterface::submit 13
EntityFormController::submitForm public function Form submission handler. Overrides FormInterface::submitForm
EntityFormController::updateFormLangcode protected function Updates the form language to reflect any change to the entity language.
EntityFormController::validateForm public function Form validation handler. Overrides FormInterface::validateForm
EntityFormController::__construct public function Constructs an EntityFormController object. 5
EntityFormControllerNG::buildEntity public function Overrides EntityFormController::buildEntity(). Overrides EntityFormController::buildEntity 2
EntityFormControllerNG::form public function Overrides EntityFormController::form(). Overrides EntityFormController::form 5
EntityFormControllerNG::submitEntityLanguage protected function Overrides EntityFormController::submitEntityLanguage(). Overrides EntityFormController::submitEntityLanguage
EntityFormControllerNG::validate public function Overrides EntityFormController::validate(). Overrides EntityFormController::validate 3