diff options
Diffstat (limited to 'modules/field/tests/field_test.entity.inc')
-rw-r--r-- | modules/field/tests/field_test.entity.inc | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/modules/field/tests/field_test.entity.inc b/modules/field/tests/field_test.entity.inc index 4c0269d3e..4273dd95f 100644 --- a/modules/field/tests/field_test.entity.inc +++ b/modules/field/tests/field_test.entity.inc @@ -413,6 +413,70 @@ function field_test_entity_form_submit_build_test_entity($form, &$form_state) { } /** + * Form combining two separate entities. + */ +function field_test_entity_nested_form($form, &$form_state, $entity_1, $entity_2) { + // First entity. + foreach (array('ftid', 'ftvid', 'fttype') as $key) { + $form[$key] = array( + '#type' => 'value', + '#value' => $entity_1->$key, + ); + } + field_attach_form('test_entity', $entity_1, $form, $form_state); + + // Second entity. + $form['entity_2'] = array( + '#type' => 'fieldset', + '#title' => t('Second entity'), + '#tree' => TRUE, + '#parents' => array('entity_2'), + '#weight' => 50, + ); + foreach (array('ftid', 'ftvid', 'fttype') as $key) { + $form['entity_2'][$key] = array( + '#type' => 'value', + '#value' => $entity_2->$key, + ); + } + field_attach_form('test_entity', $entity_2, $form['entity_2'], $form_state); + + $form['save'] = array( + '#type' => 'submit', + '#value' => t('Save'), + '#weight' => 100, + ); + + return $form; +} + +/** + * Validate handler for field_test_entity_nested_form(). + */ +function field_test_entity_nested_form_validate($form, &$form_state) { + $entity_1 = (object) $form_state['values']; + field_attach_form_validate('test_entity', $entity_1, $form, $form_state); + + $entity_2 = (object) $form_state['values']['entity_2']; + field_attach_form_validate('test_entity', $entity_2, $form['entity_2'], $form_state); +} + +/** + * Submit handler for field_test_entity_nested_form(). + */ +function field_test_entity_nested_form_submit($form, &$form_state) { + $entity_1 = (object) $form_state['values']; + field_attach_submit('test_entity', $entity_1, $form, $form_state); + field_test_entity_save($entity_1); + + $entity_2 = (object) $form_state['values']['entity_2']; + field_attach_submit('test_entity', $entity_2, $form['entity_2'], $form_state); + field_test_entity_save($entity_2); + + drupal_set_message(t('test_entities @id_1 and @id_2 have been updated.', array('@id_1' => $entity_1->ftid, '@id_2' => $entity_2->ftid))); +} + +/** * Controller class for the test_entity_bundle entity type. * * This extends the DrupalDefaultEntityController class, adding required |