function _workflow_form_alter in Workflow 7
Used to Implement hook_form_alter(). Is now a subfunction of workflow_form_BASE_FORM_ID_alter(). This is more performant, since it is called only on form with correct BASE_FORM_ID.
Parameters
object &$node:
Return value
array
See also
http://bryanbraun.com/2013/08/17/using-hook-form-base-form-id-alter
2 calls to _workflow_form_alter()
- workflow_form_comment_form_alter in ./
workflow.node.inc - Implements hook_form_BASE_FORM_ID_alter().
- workflow_form_node_form_alter in ./
workflow.node.inc - Implements hook_form_BASE_FORM_ID_alter().
File
- ./
workflow.node.inc, line 286 - Node specific functions, remnants of nodeapi.
Code
function _workflow_form_alter(&$form, &$form_state, $form_id) {
// Ignore all forms except comment forms and node editing forms.
if (isset($form['#node']) && $form_id == 'comment_node_' . $form['#node']->type . '_form' || isset($form['#node']->type) && isset($form['#node']) && $form['#node']->type . '_node_form' == $form_id) {
// Set node to #node if available or load from nid value.
$node = isset($form['#node']) ? $form['#node'] : node_load($form['nid']['#value']);
$type = $node->type;
if ($workflow = workflow_get_workflows_by_type($node->type)) {
$workflow_entities = variable_get('workflow_' . $type, 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;
}
$choices = workflow_field_choices($node);
// If this is a preview, the current state should come from
// the form values, not the node, as the user may have changed
// the state.
$current = isset($form_state['values']['workflow']) ? $form_state['values']['workflow'] : workflow_node_current_state($node);
// If the current node state is not one of the choices, pick first valid choice.
// We know all states in $choices are states that user has permission to
// go to because workflow_field_choices() has already checked that.
if (!isset($choices[$current])) {
$current = $workflow
->getFirstSid('node', $node);
}
// Stop if user has no new target state(s) to choose.
if (!workflow_show_form($current, $workflow, $choices)) {
return;
}
$name = t($workflow->name);
$form['#wf'] = $workflow;
$form['workflow'] = array(
'#type' => 'fieldset',
'#title' => $name,
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#weight' => 10,
);
$timestamp = NULL;
$comment = NULL;
// See if scheduling information is present.
if (isset($node->workflow_scheduled_timestamp) && isset($node->workflow_scheduled_sid)) {
// The default value should be the upcoming sid.
$current = $node->workflow_scheduled_sid;
$timestamp = $node->workflow_scheduled_timestamp;
$comment = $node->workflow_scheduled_comment;
}
if (isset($form_state['values']['workflow_comment'])) {
$comment = $form_state['values']['workflow_comment'];
}
// Include the 'workflow form'. $form is modified by reference.
workflow_node_form($form, $form_state, t('Change !name state', array(
'!name' => $name,
)), $name, $current, $choices, $timestamp, $comment);
}
}
}