function party_data_set_attach_form in Party 7
Same name and namespace in other branches
- 8.2 party.module \party_data_set_attach_form()
Attach attached entity forms to a form.
This takes all attached entities in the $form_state['#attached_entity'] array, runs their form callback and puts it in $form[$attached_entity->hash()]
Parameters
$standalone: Whether this is being used as a form to edit just the one attached entity. If true, the fieldset is not shown around the entity form.
3 calls to party_data_set_attach_form()
- party_attached_entity_edit_form in ./
party.pages.inc - Form to edit or create an attached entity.
- party_edit_form_form in plugins/
content_types/ party_edit_form.inc - Form
- party_form in ./
party.pages.inc - Party edit form.
File
- ./
party.module, line 1141 - Provides a generic CRM party entity.
Code
function party_data_set_attach_form(&$form, &$form_state, $data_set, $deltas = FALSE, $create = TRUE) {
// Get the form callback.
$callback = party_attached_entity_form_callback($data_set
->getDataInfo('name'));
// Create an array of the $deltas we are working with:
// If no deltas are specified assume we're using all the deltas.
if (empty($deltas) && count($data_set
->getEntityIds()) > 0) {
$deltas = array_keys($data_set
->getEntityIds());
}
elseif (empty($deltas)) {
$deltas = array(
0,
);
}
foreach ($deltas as $delta) {
$entity = $data_set
->getEntity($delta, $create);
// It is possible $entity is false as if $create was false and $delta was
// unset there would be no entity.
if (!$entity) {
continue;
}
$form_key = $data_set
->getDataInfo('name') . ':' . $delta;
$form[$form_key] = array(
'#party' => $data_set
->getParty(),
'#data_set_name' => $data_set
->getDataInfo('name'),
'#data_set' => $data_set,
'#delta' => $delta,
'#entity' => $entity,
'#parents' => array(
$form_key,
),
'#tree' => TRUE,
'#type' => 'fieldset',
'#title' => check_plain(entity_label($data_set
->getDataInfo('entity type'), $entity)),
);
$callback($form[$form_key], $form_state, $data_set, $delta, $data_set
->getParty());
}
// Save the data set in the array.
$form['#data_set_controllers'][$data_set
->getDataInfo('name')] = $data_set;
$form['#submit'][] = 'party_data_set_attach_form_submit';
$form['#validate'][] = 'party_data_set_attach_form_validate';
}