function _workflownode_form_alter in Workflow 7.2
Helper function to implement hook_form_alter().
Is now a subfunction of workflow_form_BASE_FORM_ID_alter(). This is more performant (compared to 7.x-1.2 and before), since it is called only on form with correct BASE_FORM_ID.
See also
http://bryanbraun.com/2013/08/17/using-hook-form-base-form-id-alter
2 calls to _workflownode_form_alter()
- workflownode_form_comment_form_alter in workflow_node/
workflownode.module - Implements hook_form_BASE_FORM_ID_alter().
- workflownode_form_node_form_alter in workflow_node/
workflownode.module - Implements hook_form_BASE_FORM_ID_alter().
File
- workflow_node/
workflownode.module, line 307 - Hooks and functions for the 'conventional' (version D5/D6/D7.1) Workflow Node, remnants of nodeapi.
Code
function _workflownode_form_alter(&$form, &$form_state, $form_id) {
// Set node to #node if available or load from nid value.
$node = isset($form['#node']) ? $form['#node'] : node_load($form['nid']['#value']);
$bundle = $node->type;
$entity = $node;
$entity_type = 'node';
$field_name = '';
// Skip if there are no Node API workflows.
if (!workflow_get_workflow_type_map_by_type($bundle)) {
return;
}
if ($workflow = workflow_get_workflows_by_type($bundle, 'node')) {
$workflow_entities = variable_get('workflow_' . $bundle, array());
// Abort if the entity type of the form is not in the list that the user
// wants to display the workflow form on.
if (!in_array($form['#entity_type'], $workflow_entities)) {
return;
}
/*
$form['#wf'] = $workflow;
$form['workflow'] = array(
'#type' => 'fieldset',
'#title' => check_plain($label),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#weight' => 10,
);
*/
// Emulate a Field API interface.
// Show the current state and the Workflow form to allow state changing.
// N.B. This part is replicated in hook_node_view, workflow_tab_page, etc.
if ($workflow) {
$field = _workflow_info_field($field_name, $workflow);
$field_name = $field['field_name'];
$field_id = $field['id'];
$instance = field_info_instance($entity_type, $field_name, $bundle);
if (!$field_id) {
// This is a Workflow Node workflow. Set widget options as in v7.x-1.2
$field['settings']['widget']['comment'] = isset($workflow->options['comment_log_node']) ? $workflow->options['comment_log_node'] : 1;
// vs. ['comment_log_tab'];
$field['settings']['widget']['current_status'] = TRUE;
}
}
// Do not include the default 'Update Workflow' button, since we are already in an Edit form.
$instance['widget']['settings']['submit_function'] = '';
// Include the 'workflow form'. $form is modified by reference.
$form = workflow_transition_form($form, $form_state, $field, $instance, $entity_type, $entity);
}
}