Commit 4cc8ae69 authored by webchick's avatar webchick

#830704 by fago, effulgentsia, Frando: Fixed entity forms cannot be properly extended.

parent 9abb496d
......@@ -7433,16 +7433,20 @@ function entity_form_field_validate($entity_type, $form, &$form_state) {
*
* 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
* $form['#builder_function'] for doing this, appropriate for the particular
* entity and form. Many of these 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_submit() to copy field data.
* 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_submit() 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
* 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) {
......@@ -7457,6 +7461,13 @@ function entity_form_submit_build_entity($entity_type, $entity, $form, &$form_st
$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) {
$function($entity_type, $entity, $form, $form_state);
}
}
// Copy field values to the entity.
if ($info['fieldable']) {
field_attach_submit($entity_type, $entity, $form, $form_state);
......
......@@ -2003,7 +2003,6 @@ function comment_form($form, &$form_state, $comment) {
// Attach fields.
$comment->node_type = 'comment_node_' . $node->type;
$form['#builder_function'] = 'comment_form_submit_build_comment';
field_attach_form('comment', $comment, $form, $form_state);
return $form;
......@@ -2013,7 +2012,7 @@ function comment_form($form, &$form_state, $comment) {
* Build a preview from submitted form values.
*/
function comment_form_build_preview($form, &$form_state) {
$comment = $form['#builder_function']($form, $form_state);
$comment = comment_form_submit_build_comment($form, $form_state);
$form_state['comment_preview'] = comment_preview($comment);
$form_state['rebuild'] = TRUE;
}
......@@ -2154,7 +2153,7 @@ function comment_submit($comment) {
/**
* Updates the form state's comment entity by processing this submission's values.
*
* This is the default #builder_function for the comment form. It is called
* This is the default builder function for the comment form. It is called
* during the "Save" and "Preview" submit handlers to retrieve the entity to
* save or preview. This function can also be called by a "Next" button of a
* wizard to update the form state's entity with the current step's values
......@@ -2174,7 +2173,7 @@ function comment_form_submit_build_comment($form, &$form_state) {
*/
function comment_form_submit($form, &$form_state) {
$node = node_load($form_state['values']['nid']);
$comment = $form['#builder_function']($form, $form_state);
$comment = comment_form_submit_build_comment($form, $form_state);
if (user_access('post comments') && (user_access('administer comments') || $node->comment == COMMENT_NODE_OPEN)) {
// Save the anonymous user information to a cookie for reuse.
if (!$comment->uid) {
......
......@@ -355,7 +355,6 @@ function field_test_entity_form($form, &$form_state, $entity, $add = FALSE) {
}
// Add field widgets.
$form['#builder_function'] = 'field_test_entity_form_submit_builder';
field_attach_form('test_entity', $entity, $form, $form_state);
if (!$add) {
......@@ -387,7 +386,7 @@ function field_test_entity_form_validate($form, &$form_state) {
* Submit handler for field_test_entity_form().
*/
function field_test_entity_form_submit($form, &$form_state) {
$entity = $form['#builder_function']($form, $form_state);
$entity = field_test_entity_form_submit_build_test_entity($form, $form_state);
$insert = empty($entity->ftid);
field_test_entity_save($entity);
......@@ -407,7 +406,7 @@ function field_test_entity_form_submit($form, &$form_state) {
/**
* Updates the form state's entity by processing this submission's values.
*/
function field_test_entity_form_submit_builder($form, &$form_state) {
function field_test_entity_form_submit_build_test_entity($form, &$form_state) {
$entity = $form_state['test_entity'];
entity_form_submit_build_entity('test_entity', $entity, $form, $form_state);
return $entity;
......
......@@ -306,9 +306,7 @@ function node_form($form, &$form_state, $node) {
}
$form += array('#submit' => array());
$form['#builder_function'] = 'node_form_submit_build_node';
field_attach_form('node', $node, $form, $form_state, $node->language);
return $form;
}
......@@ -327,7 +325,7 @@ function node_form_delete_submit($form, &$form_state) {
function node_form_build_preview($form, &$form_state) {
$node = $form['#builder_function']($form, $form_state);
$node = node_form_submit_build_node($form, $form_state);
$form_state['node_preview'] = node_preview($node);
$form_state['rebuild'] = TRUE;
}
......@@ -410,7 +408,7 @@ function theme_node_preview($variables) {
}
function node_form_submit($form, &$form_state) {
$node = $form['#builder_function']($form, $form_state);
$node = node_form_submit_build_node($form, $form_state);
$insert = empty($node->nid);
node_save($node);
$node_link = l(t('view'), 'node/' . $node->nid);
......@@ -443,7 +441,7 @@ function node_form_submit($form, &$form_state) {
/**
* Updates the form state's node entity by processing this submission's values.
*
* This is the default #builder_function for the node form. It is called
* This is the default builder function for the node form. It is called
* during the "Save" and "Preview" submit handlers to retrieve the entity to
* save or preview. This function can also be called by a "Next" button of a
* wizard to update the form state's entity with the current step's values
......
......@@ -642,7 +642,6 @@ function taxonomy_form_term($form, &$form_state, $edit = array(), $vocabulary =
$form['#term'] = (array) $term;
$form['#term']['parent'] = $parent;
$form['#vocabulary'] = $vocabulary;
$form['#builder_function'] = 'taxonomy_form_term_submit_builder';
// Check for confirmation forms.
if (isset($form_state['confirm_delete'])) {
......@@ -792,7 +791,7 @@ function taxonomy_form_term_submit($form, &$form_state) {
return;
}
$term = $form['#builder_function']($form, $form_state);
$term = taxonomy_form_term_submit_build_taxonomy_term($form, $form_state);
$status = taxonomy_term_save($term);
switch ($status) {
......@@ -835,7 +834,7 @@ function taxonomy_form_term_submit($form, &$form_state) {
/**
* Updates the form state's term entity by processing this submission's values.
*/
function taxonomy_form_term_submit_builder($form, &$form_state) {
function taxonomy_form_term_submit_build_taxonomy_term($form, &$form_state) {
$term = $form_state['term'];
entity_form_submit_build_entity('taxonomy_term', $term, $form, $form_state);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment