1

How can I programmatically access and alter the Workflow module settings with hook_form_alter() on a node edit form?

I can see the Workflow] module settings in its own field-set on the node edit form, but I cannot find any mention of it when I look at the output of dd($form), dd($form_state), or dpm($form).

I would have expected to find it somewhere similar to the following.

$form['edit_workflow']['value'];

2 Answers 2

0

$form['workflow'] is accessible using #after_build within the Form API.

function hook_form_alter($form, &$form_state) {
    $form['#after_build'][] = '_manage_workflow';
}

function _manage_workflow($form, &$form_state) {
    $form['workflow'] = ''; //Do workflow alterations here...
    return $form;
}
1
  • I figured this would work in D6 as well, but setting a #default_value on the workflow never seems to work. Any ideas out there? Commented Apr 10, 2014 at 18:10
0

It seems your implementation of hook_form_alter() runs before the one provided by the Workflow module. Implement hook_module_implements_alter() to change the order in which implementations of hook_form_alter() are executed. Alternatively, give your module a higher weight than the Workflow has.

Beware that this approach does not work for changing the order of implementations of hook_form_FORM_ID_alter() specifically. Implementations of hook_form_FORM_ID_alter() are always executed in the same order as those of hook_form_alter(). This is due to the way how drupal_prepare_form() calls drupal_alter().

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.