function civicrm_entity_form in CiviCRM Entity 7
Same name and namespace in other branches
- 7.2 civicrm_entity.default_form.inc \civicrm_entity_form()
1 string reference to 'civicrm_entity_form'
- CivicrmEntityUIController::hook_forms in ./
civicrm_entity_ui_controller.inc - Always use the same civicrm_entity_form
File
- ./
civicrm_entity.module, line 509 - Implement CiviCRM entities as a Drupal Entity.
Code
function civicrm_entity_form($form, &$form_state, $entity, $op, $entity_type) {
// Add the field related form elements.
$form_state['entity'] = new CivicrmEntity((array) $entity, $entity_type);
field_attach_form($entity_type, $entity, $form, $form_state);
//not quite sure why these are not being added but ....
$wrapper = entity_metadata_wrapper($entity_type);
foreach ($wrapper as $name => $child) {
$info = $child
->info();
$form[$name] = array(
'#type' => $info['type'],
'#title' => $info['label'],
'#description' => !empty($info['description']) ? $info['description'] : '',
);
}
$form['actions'] = array(
'#type' => 'container',
'#attributes' => array(
'class' => array(
'form-actions',
),
),
'#weight' => 400,
);
$form['#validate'] = array();
$form['#submit'] = array();
$form['#validate'][] = 'civicrm_entity_form_validate';
$form['#submit'][] = 'civicrm_entity_form_submit';
// We add the form's #submit array to this button along with the actual submit
// handler to preserve any submit handlers added by a form callback_wrapper.
$submit = array();
if (!empty($form['#submit'])) {
$submit += $form['#submit'];
}
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
'#submit' => $submit + array(),
);
return $form;
}