On the node view page, if I click on a state change button, I get the error message "Comment field is required." I did specify a value in the Workflow comment box, but not in the Comment comment box.

CommentFileSizeAuthor
#4 1884630.patch3.43 KBNancyDru
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

NancyDru’s picture

I think this is because workflow_form_alter() adds the workflow form to the comment form. Comments and workflow should be separate. Perhaps using hook_node_view() would be more appropriate?

NancyDru’s picture

Indeed, I set comments to a separate page, and when going to the add comment page, there is the workflow-tab display. IMHO, it has no business being on a separate comment page. Workflows belong to nodes, not comments.

NancyDru’s picture

Try this:

/**
 * Implements hook_node_view().
 *
 * @param object $node.
 * @param string $view_mode.
 * @param string $langcode.
 *
 * @return renderable content in $node->content array.
 */
function workflow_node_view($node, $view_mode, $langcode) {
  if ($view_mode != 'full') {
    return;
  }

  $workflow = workflow_get_workflow_type_map_by_type($node->type);
  $states = array();
  foreach (workflow_get_workflow_states() as $data) {
    $states[$data->sid] = check_plain(t($data->state));
  }

  $current = workflow_node_current_state($node);

  // Pull in tab form.
  module_load_include('inc', 'workflow', 'workflow.pages');

  // Show current state at the top of the node display.
  $markup = '<span class="workflow-current-state">'
    . t('Current state: @state', array('@state' => $states[$current]))
    . '</span>';

  $node->content['workflow_current_state'] = array(
    '#markup' => $markup,
    '#weight' => -99,
    );

  // Show state change form at the bottom of the node display.
  $form = drupal_get_form('workflow_tab_form', $node, $workflow->wid, $states, $current);
  $form['#weight'] = 99;

  $node->content['workflow'] = $form;
}

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)) {

BTW, if this is accepted, it might be better to move workflow.pages.inc into the main module.

NancyDru’s picture

Status: Active » Needs review
FileSize
3.43 KB
NancyDru’s picture

Status: Needs review » Fixed

Committed to 7.x-1.x-dev.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

coreyp_1’s picture

Just posting a cross-reference where this patch has caused a different bug: #1975058: Workflow is no longer added to Comment form