diff options
author | Angie Byron <webchick@24967.no-reply.drupal.org> | 2010-11-20 06:49:47 +0000 |
---|---|---|
committer | Angie Byron <webchick@24967.no-reply.drupal.org> | 2010-11-20 06:49:47 +0000 |
commit | 4cc8ae69a1df3d7ac1f33122c1a6afa6ba65fc0f (patch) | |
tree | fef7107ec164b66c946453221d33ed5ccd193450 | |
parent | 9abb496d8a32da3e644d6c0095a89d76544ba211 (diff) | |
download | brdo-4cc8ae69a1df3d7ac1f33122c1a6afa6ba65fc0f.tar.gz brdo-4cc8ae69a1df3d7ac1f33122c1a6afa6ba65fc0f.tar.bz2 |
#830704 by fago, effulgentsia, Frando: Fixed entity forms cannot be properly extended.
-rw-r--r-- | includes/common.inc | 25 | ||||
-rw-r--r-- | modules/comment/comment.module | 7 | ||||
-rw-r--r-- | modules/field/tests/field_test.entity.inc | 5 | ||||
-rw-r--r-- | modules/node/node.pages.inc | 8 | ||||
-rw-r--r-- | modules/taxonomy/taxonomy.admin.inc | 5 |
5 files changed, 28 insertions, 22 deletions
diff --git a/includes/common.inc b/includes/common.inc index 4ad8e08d8..c8848f5cd 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -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); diff --git a/modules/comment/comment.module b/modules/comment/comment.module index 31738a566..2e9b86ade 100644 --- a/modules/comment/comment.module +++ b/modules/comment/comment.module @@ -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) { diff --git a/modules/field/tests/field_test.entity.inc b/modules/field/tests/field_test.entity.inc index 37695bd49..4c0269d3e 100644 --- a/modules/field/tests/field_test.entity.inc +++ b/modules/field/tests/field_test.entity.inc @@ -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; diff --git a/modules/node/node.pages.inc b/modules/node/node.pages.inc index 166a510c7..261ac5c67 100644 --- a/modules/node/node.pages.inc +++ b/modules/node/node.pages.inc @@ -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 diff --git a/modules/taxonomy/taxonomy.admin.inc b/modules/taxonomy/taxonomy.admin.inc index 52cecb298..63729fbb1 100644 --- a/modules/taxonomy/taxonomy.admin.inc +++ b/modules/taxonomy/taxonomy.admin.inc @@ -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); |