function commerce_message_message_form in Commerce Message 7
Form callback: create/edit a message.
1 string reference to 'commerce_message_message_form'
- commerce_message_handler_area_add_message::render in includes/
views/ handlers/ commerce_message_handler_area_add_message.inc - Render the area.
File
- includes/
commerce_message.message.inc, line 486
Code
function commerce_message_message_form($form, &$form_state, $entity, $valid_types = array(), $current_display = 'order_view') {
$form['#entity'] = $entity;
$form['content'] = array(
'#type' => 'fieldset',
'#title' => t('Add new comment'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
// Store the current_display in order to return the currend view display.
$form['#current_display'] = array(
'#type' => 'value',
'#value' => $current_display,
);
$options = array();
foreach (message_type_load() as $name => $message_type) {
if (empty($valid_types) || in_array($name, $valid_types)) {
$options[$name] = check_plain($message_type->description);
}
}
if (count($options) == 1) {
$option_names = array_keys($options);
$form['#entity']->type = $option_names[0];
}
else {
$form['content']['type'] = array(
'#type' => 'select',
'#title' => t('Type'),
'#options' => $options,
'#default_value' => $entity->type,
'#process' => array(
'_commerce_message_message_type_select_process',
'ajax_process_form',
),
'#element_validate' => array(
'_commerce_message_message_type_select_element_validate',
),
'#ajax' => array(
'callback' => '_commerce_message_message_type_select_ajax_callback',
'method' => 'replace',
),
'#weight' => -10,
);
}
field_attach_form('message', $form['#entity'], $form['content'], $form_state);
$form['content']['actions'] = array(
'#type' => 'container',
'#attributes' => array(
'class' => array(
'form-actions',
),
),
'#weight' => 400,
);
// 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.
$form['content']['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
'#submit' => (!empty($form['#submit']) ? $form['#submit'] : array()) + array(
'commerce_message_message_form_submit',
),
'#ajax' => array(
'callback' => '_commerce_message_message_submit_ajax_callback',
),
);
// We append the validate handler to #validate in case a form callback_wrapper
// is used to add validate handlers earlier.
$form['#validate'][] = 'commerce_message_message_form_validate';
return $form;
}