1 field_test.entity.inc | field_test_entity_nested_form($form, &$form_state, $entity_1, $entity_2) |
Form combining two separate entities.
File
- core/
modules/ field/ tests/ field_test/ field_test.entity.inc, line 423 - Defines an entity type.
Code
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;
}