diff --git a/core/includes/entity.inc b/core/includes/entity.inc index b6b92b0..a29a7e8 100644 --- a/core/includes/entity.inc +++ b/core/includes/entity.inc @@ -522,52 +522,6 @@ function entity_get_form(EntityInterface $entity, $operation = 'default', array } /** - * Copies submitted values to entity properties for simple entity forms. - * - * During the submission handling of an entity form's "Save", "Preview", and - * possibly other buttons, the form state's entity needs to be updated with the - * submitted form values. Each entity form implements its own builder function - * for doing this, appropriate for the particular entity and form, whereas - * modules may specify additional builder functions in $form['#entity_builders'] - * for copying the form values of added form elements to entity properties. - * Many of the main entity builder functions can call this helper function to - * re-use its logic of copying $form_state['values'][PROPERTY] values to - * $entity->PROPERTY for all entries in $form_state['values'] that are not - * field data, and calling field_attach_extract_form_values() to copy field - * data. Apart from that this helper invokes any additional builder functions - * that have been specified in $form['#entity_builders']. - * - * For some entity forms (e.g., forms with complex non-field data and forms that - * simultaneously edit multiple entities), this behavior may be inappropriate, - * so the builder function for such forms needs to implement the required - * functionality instead of calling this function. - */ -function entity_form_submit_build_entity($entity_type, $entity, $form, &$form_state, array $options = array()) { - $info = entity_get_info($entity_type); - - // Copy top-level form values that are not for fields to entity properties, - // without changing existing entity properties that are not being edited by - // this form. Copying field values must be done using - // field_attach_extract_form_values(). - $values_excluding_fields = $info['fieldable'] ? array_diff_key($form_state['values'], field_info_instances($entity_type, $entity->bundle())) : $form_state['values']; - foreach ($values_excluding_fields as $key => $value) { - $entity->set($key, $value); - } - - // Invoke all specified builders for copying form values to entity properties. - if (isset($form['#entity_builders'])) { - foreach ($form['#entity_builders'] as $function) { - call_user_func_array($function, array($entity_type, $entity, &$form, &$form_state)); - } - } - - // Copy field values to the entity. - if ($info['fieldable']) { - field_attach_extract_form_values($entity, $form, $form_state, $options); - } -} - -/** * Returns an entity list controller for a given entity type. * * @param string $entity_type diff --git a/core/lib/Drupal/Core/Entity/EntityFormController.php b/core/lib/Drupal/Core/Entity/EntityFormController.php index 570dfe5..f384e16 100644 --- a/core/lib/Drupal/Core/Entity/EntityFormController.php +++ b/core/lib/Drupal/Core/Entity/EntityFormController.php @@ -355,9 +355,24 @@ public function buildEntity(array $form, array &$form_state) { // the controller to be the one before caching. Ensure to have the // controller of the current request. $form_state['controller'] = $this; - // @todo Move entity_form_submit_build_entity() here. - // @todo Exploit the Field API to process the submitted entity field. - entity_form_submit_build_entity($entity->entityType(), $entity, $form, $form_state, array('langcode' => $this->getFormLangcode($form_state))); + + // Copy top-level form values to entity properties, without changing + // existing entity properties that are not being edited by + // this form. + // @todo: This relies on a method that only exists for config and content + // entities, in a different way. Consider moving this logic to a config + // entity specific implementation. + foreach ($form_state['values'] as $key => $value) { + $entity->set($key, $value); + } + + // Invoke all specified builders for copying form values to entity properties. + if (isset($form['#entity_builders'])) { + foreach ($form['#entity_builders'] as $function) { + call_user_func_array($function, array($entity->entityType(), $entity, &$form, &$form_state)); + } + } + return $entity; } diff --git a/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkFormController.php b/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkFormController.php index 8aea21d..dbd8065 100644 --- a/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkFormController.php +++ b/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkFormController.php @@ -252,6 +252,34 @@ public function validate(array $form, array &$form_state) { } /** + * {@inheritdoc} + */ + public function buildEntity(array $form, array &$form_state) { + // @todo: Remove this when menu links are content entities. + $entity = clone $this->entity; + // If you submit a form, the form state comes from caching, which forces + // the controller to be the one before caching. Ensure to have the + // controller of the current request. + $form_state['controller'] = $this; + + // Copy top-level form values to entity properties, without changing + // existing entity properties that are not being edited by + // this form. + foreach ($form_state['values'] as $key => $value) { + $entity->$key = $value; + } + + // Invoke all specified builders for copying form values to entity properties. + if (isset($form['#entity_builders'])) { + foreach ($form['#entity_builders'] as $function) { + call_user_func_array($function, array($entity->entityType(), $entity, &$form, &$form_state)); + } + } + + return $entity; + } + + /** * Overrides EntityFormController::submit(). */ public function submit(array $form, array &$form_state) {