The state buttons are rendering above the comment box. See attached screen shot.

CommentFileSizeAuthor
workflow_buttons_misplaced.jpg84.96 KBnancydru

Comments

nancydru’s picture

Priority: Normal » Major

The above was in the node view mode.

In the edit screen, the buttons are at the top of the edit screen while the comment box is at the bottom.

nancydru’s picture

Project: Workflow » Workflow Extensions

Moving to extensions

nancydru’s picture

This takes care of my situation:

  function _workflow_extensions_replace_with_buttons(&$form, $workflow_name) {
    $current_sid = $form['workflow'][$workflow_name]['#default_value'];
    $current_state_name = workflow_get_workflow_states_by_sid($current_sid)->state;
  
    // We need a node-context for token replacement. When on the Workflow tab
    // form, the node object will already have been loaded on the form.
    // When creating content (node/add/<type>) we only have limited data. In
    // the remaining cases we load the node from the cache based on the nid
    // found on the form.
    $form_id = $form['form_id']['#value'];
    if (strpos($form_id, 'workflow_tab_form') === 0) {
      $node = $form['node']['#value'];
    }
    elseif (is_numeric($nid = $form['nid']['#value'])) {
      $node = node_load($nid);
    }
    else { // Creating new content, nid not yet known
      $node = $form['#node'];
    }
    $states = $form['workflow'][$workflow_name]['#options'];
    $submit_handlers = _workflow_extensions_assign_handlers($form);
+    $form['workflow']['buttons'] = array('#prefix' => '<div class="workflow-buttons">', '#suffix' => '</div>');
  
    foreach ($states as $sid => $to_state_name) {
      if ($sid != $current_sid) {
        // Create button for transition from current_sid to destination state.
        $button = array();
        $button['#value'] = workflow_extensions_get_transition_label($form['#wf']->wid, $current_state_name, workflow_get_workflow_states_by_sid($sid)->state, $node);
        $button['#type'] = 'submit';
        $button['#to_state'] = $sid;
        if (isset($form['buttons']['submit']['#weight'])) { // node form
          $button['#weight'] = $form['buttons']['submit']['#weight'] + 1;
        }
        elseif (isset($form['submit']['#weight'])) { // comment form
          $button['#weight'] = $form['submit']['#weight'];
        }
        $button['#submit'] = $submit_handlers;
-        $form['buttons']["submit_to_$to_state_name"] = $button;
+        $form['workflow']['buttons']["submit_to_$to_state_name"] = $button;
      }
    }
    // Get rid of workflow radio buttons that live inside the fieldset
    unset($form['workflow'][$workflow_name]);
    // If after this the fieldset is empty, remove it altogher
    if (!isset($form['workflow']['workflow_scheduled']) &&
      (!isset($form['workflow']['workflow_comment']) || $form['workflow']['workflow_comment']['#type'] == 'hidden')) {
      unset($form['workflow']);
    }
    // With the existing Save button now impotent to submit a workflow
    // transition, we can re-purpose it for saving all other edits to the
    // node without changing the workflow state.
    // This does not make sense for the Workflow tab form though, as there is
    // nothing to save but a state change. In this case we simply remove the
    // Save button.
    if ($form_id == 'comment_form') {
      $form['actions']['submit'] = $form['submit']; // ???
      $form['actions']['submit']['#submit'] = $form['#submit'];
      $form['actions']['submit']['#weight']--; // left-most
    }
    if (strpos($form_id, 'workflow_tab_form') !== 0 && ($label = variable_get('workflow_extensions_default_save_button_label', ''))) {
      $form['actions']['submit']['#value'] = workflow_extensions_replace_state_name_tokens($label, $current_state_name);
    }
    unset($form['submit']);    // remove submit button...
    //unset($form['#submit']); // ... but don't remove handler, #1097328: Menu changes are not saved
  }
nancydru’s picture

This is not a problem with the code proposed in #1884630: State update conflicts with Comment form.

nancydru’s picture

Status: Active » Closed (works as designed)

That issue has been fixed.

dbassendine’s picture

Status: Closed (works as designed) » Active

I'm also seeing the buttons displaced, but the patch from http://drupal.org/node/1884630#comment-6943026 did not resolve this for me. The patch you gave in #3 does work, however. +1 for committing this to workflow extensions.

Thanks, David

nancydru’s picture

I would recommend that you download the -dev version of Workflow that will roll out in a few minutes.

rdeboer’s picture

I agree with NancyDru that the "Single action" buttons provided by Workflow Extensions on the node edit form do not (or no longer) appear in the workflow field set, amongst the "Schedule" radio-buttons and "Comment" field, whereas "classic radio" and "dropdown selector" do.

I've just done a checkout from the Git repository of the latest version of Workflow 7.x-1.x-dev. This should include #1884630: State update conflicts with Comment form, right?

I find the same as dbassendine, #6, that the patch of #4 does not have the claimed effect on the "Single action" buttons.

I wiil apply the patch of #3 and report back.

Rik

rdeboer’s picture

Title: State buttons misplaced » State change single-action buttons misplaced on node edit form
Assigned: Unassigned » rdeboer
Priority: Major » Normal
Status: Active » Fixed

Well that seemed to work.
Committed with attribution.
Thanks Nancy.
Rik

rdeboer’s picture

Actually... They now don't work on the Edit form any longer. But they do work on the View and Workflow tabs of the node.

nancydru’s picture

Line 362: $form['workflow']['buttons']["submit_to_$to_state_name"] = $button;

rdeboer’s picture

Yep. thanks.
We came to the same conclusion. Already released in 7.x-1.0-beta2 -- forgot to update the issue.
Rik

Status: Fixed » Closed (fixed)

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