In Workbench Moderation, edited versions of published nodes are saved as "draft". When clicking the "View draft" tab, which calls a URI like http://example.org/node/5/draft, a very basis 404 page is displayed:

  <html><head></head><body>404 Not Found</body></html>

The problem can be traced to the call in workbench_moderation.node.inc

  $router_item = menu_get_item('node/' . $node->nid);

which returns "restws_page_callback" for $router_item['page_callback']. (In a standard installation without restws, the return value is "node_page_view", and all works fine.)

The cause of the problem seems to be on lines 295 ff. of restws.module:

  // @todo: Determine human readable URIs and redirect, if there is no
  // page callback.
  if (isset($page_callback)) {
    // Further page callback arguments have been appended to our arguments.
    $args = func_get_args();
    return call_user_func_array($page_callback, array_slice($args, 2));
  }
  echo '404 Not Found';
  drupal_add_http_header('Status', '404 Not Found');
  drupal_page_footer();
  exit;

Issue #1343816: Unconditional altering and overriding of existing menu links breaks comment permalinks and possibly others may be related to this one.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jneubert’s picture

The attached patch is a workarround specifically for nodes.

jneubert’s picture

Status: Active » Needs review
jneubert’s picture

Version: 7.x-1.0 » 7.x-1.2

Same issue with 7.x-1.2

jneubert’s picture

#1: restws-callback-1838640-1.patch queued for re-testing.

klausi’s picture

Version: 7.x-1.2 » 7.x-2.x-dev

The 1.x branch is frozen and receives security updates only, please test against the 2.x branch.

jneubert’s picture

Issue occurs on 2.x also - patch adapted.

klausi’s picture

Project: RESTful Web Services » Workbench Moderation
Version: 7.x-2.x-dev » 7.x-1.x-dev
Status: Needs review » Needs work

The problem is that workbench moderation does not invoke the menu callback correctly, the page arguments are missing.

paddy_deburca’s picture

Not understanding the method that page arguments are passed between callbacks, I came up with the following code to solve _my_ problem between workbench_moderation and restws. in workbench_moderation.node.inc

function workbench_moderation_router_item_page_callback($node) {
  $router_item = menu_get_item('node/' . $node->nid);
  if ($router_item['include_file']) {
    require_once DRUPAL_ROOT . '/' . $router_item['include_file'];
  }

  // Call whatever function is assigned to the main node path but pass the
  // current node as an argument. This approach allows for the reuse of of Panel
  // definition acting on node/%node.
  return $router_item['page_callback']($node, 'node_page_view', $node);

}
JeebsUK’s picture

Issue summary: View changes

Any idea if the suggested fix is likely to be confirmed as a potential valid solution? I'm currently working on a site where this is an issue but an awful lot of debugging is going to have to be done to ascertain whether we think this won't break or affect other things.

artsakenos’s picture

Version: 7.x-1.x-dev » 7.x-1.3
Status: Needs work » Needs review
FileSize
659 bytes

I am working with

  • Drupal 7.28
  • Workbench Moderation 7.x-1.3 (2013-Jan-18)
  • Restws 7.x-2.1 (2013-Aug-07)

I tried:

  1. updating to workbench_moderation 7.x-2.x-dev (2013-Oct-26), installing state_machine, state_flow with version 2.99+ as required, it didn't work, giving on a draft page call Fatal error: Call to undefined function state_flow_entity_load_state_machine() in state_flow/state_flow.module on line 78
  2. 7.x-1.x-dev (2014-Jun-24): idem as above
  3. updated restws to 7.x-2.x-dev (2014-Jun-15): no wanted results
  4. applied the two restws patch posted above in #1, #6: no results

Then I built a patch according to suggestions in comment #8.
I performed some non exhaustive test on nodes and menu callbacks invoking, it works. Placing in review queue.

JeebsUK’s picture

Works for us too - but we haven't performed exhaustive testing either.

rv0’s picture

Fixes it for me. Didn't perform any heavy testing.

das-peter’s picture

menu.inc's menu_execute_active_handler does it this way: call_user_func_array($router_item['page_callback'], $router_item['page_arguments'])

I guess we should be as close as possible to that with the code in workbench_moderation_router_item_page_callback().

DamienMcKenna’s picture

Version: 7.x-1.3 » 7.x-1.x-dev

Does it still apply against v7.x-1.x-dev?

rohit0122’s picture

Hello Friends,

While working with restws module, I came across a issue of "Node view draft" page is showing blank.

And at the same time if I try to access some other page I got warning of "Illegal offset type in restws_get_resource_info()" as follow:

Illegal offset type in restws_get_resource_info()

For fixing such problem I have modify patch "workbench_moderation-fix_callback_argument-1838640-10.patch" a bit.

And after applying my modified patch, my issue get resolved.

Below is my patch file:
workbench_moderation-node_view_draft_page_fix-for-restws-mp-1356.patch

Regards,
Rohit S

dsteplight’s picture

i just want to add that #1 also works for the 7.x-2.2 branch of the RESTful web services except the change needs to happen near line 372.

dafeder’s picture

#16 worked for me on 7.x-2.3

Status: Needs review » Needs work
mallezie’s picture

Status: Needs work » Needs review
FileSize
656 bytes

I rerolled the patch in #16 to apply, the fix looks correct, and fixes the issues. This is the same of #10 (without an extra newline), and this should normally apply.

Status: Needs review » Needs work

The last submitted patch, 20: wb_moderation_restws-1838640-20.patch, failed testing.

aschmoe’s picture

Status: Needs work » Needs review
FileSize
588 bytes

Not sure why #20 is failing, here it is re-rolled today.

mallezie’s picture

aschmoe, my patch uses the string 'node' as the first argument of the callback. You're patch creates warnings on the draft pages from rest-ws not able to define the resources.
Let's test attached patch which uses the callback approach from menu.inc as suggested in #13. It actually passes the same params as in #20 ('string node', string 'node_page_view', and node object).

mallezie’s picture

And this does indeed pass tests. Yes!

jneubert’s picture

#23 works fine for me with 7.x-1.3 and 7.x-1.4 - thanks!

zoheir.nabavi’s picture

#23 worked nicely. Thank you. How do we go about putting this in a dev branch?

mallezie’s picture

@znabavi, if this works you could set it to RTBC, and then one of the maintainers could commit this.

zoheir.nabavi’s picture

Status: Needs review » Reviewed & tested by the community
dgtlmoon’s picture

+1 tested and working here, please commit

acouch’s picture

Double confirming this fixes the issue.

dkinzer’s picture

Thanks @mallezie. This is fixing the issue for us.

daemonchrist’s picture

Status: Reviewed & tested by the community » Needs work

I tried the patch in #23 and found that it broke the View links under the Moderate tab: they all show only the currently published revision rather than the expected previous revisions. Is anyone else seeing this behavior, or is it just me?

Everything works as expected after reverting to the current stable release (with Restful web services disabled).

jonas.fa’s picture

FileSize
31.93 KB

#23 patch works with estws-7x-2.4 and workbench_moderation-7.x-1.4.

@daemonchrist

We are using the above versions, and the "View"-links under the Moderate tab are working fine.

jonas.fa’s picture

Edit:
#23 does indeed break the "View"-links under Moderate tab. No matter which "View"-link is clicked, the same content is shown.

#10 do not have this behavior.

jonas.fa’s picture

I've found that replacing the $router['page_arguments'][2] with the $node argument in the workbench_moderation_router_item_page_callback() function, solves the problem described by #32.

The node return by menu_get_item() are the published node. Hence the use of $router_item['page_arguments'] in the fixed return call, always yield the same node content.

Anyone care to comment on the legitimacy of this hack?

/**
 * Get the menu router item for nodes.
 *
 * @param $node
 *   The node being acted upon.
 * @return
 *   A fully themed node page.
 */
function workbench_moderation_router_item_page_callback($node) {
  $router_item = menu_get_item('node/' . $node->nid);
  if ($router_item['include_file']) {
    require_once DRUPAL_ROOT . '/' . $router_item['include_file'];
  }

  //replace published revision with the passed node
  $router_item['page_arguments'][2] = $node;

  // Call whatever function is assigned to the main node path but pass the
  // current node as an argument. This approach allows for the reuse of of Panel
  // definition acting on node/%node.
  return call_user_func_array($router_item['page_callback'], $router_item['page_arguments']);

}
Dave Reid’s picture

Issue summary: View changes

This definitely breaks the 'View draft' functionality for nodes, you see the published version and not the actual draft because we're no longer actually passing $node object (which contains the draft version) into the page callback.

Dave Reid’s picture

It's a shame that restws has to *prepend* it's page arguments instead of adding them on to the end, because it would be a lot easier to just have $page_arguments[0] = $node but we cannot rely on it being argument 0 with restws.

Dave Reid’s picture

Issue tags: +Needs tests

Since the previous patches broke functionality but passed tests, we need tests to cover this condition.

dgtlmoon’s picture

Dave - got a summary of the functionality it broke?

Dave Reid’s picture

  • Dave Reid committed 6356bd2 on 7.x-1.x
    Issue #1838640 by jneubert, mallezie, Dave Reid, rohit0122, artsakenos,...
Dave Reid’s picture

Status: Needs review » Needs work

Committed the fix for now.

  • Dave Reid committed 6356bd2 on 7.x-3.x
    Issue #1838640 by jneubert, mallezie, Dave Reid, rohit0122, artsakenos,...
dgtlmoon’s picture

Ah, can you slow down a bit please, you are committing things that are in 'need work' and not updating their status after

Dave Reid’s picture

No, I committed it from Needs Review after I've been personally using it on a couple sites in production, so I felt confident in it. I'm working on the tests for this, which is why I marked it to Need work after commit.

Dave Reid’s picture

Issue summary: View changes
Status: Needs work » Needs review
Issue tags: -Needs tests
FileSize
3.63 KB

This should add test coverage for the fix, and with a partial revert of my fix shows that the new test fails.

Status: Needs review » Needs work

The last submitted patch, 46: 1838640-test-failure.patch, failed testing.

The last submitted patch, 46: 1838640-test-failure.patch, failed testing.

Dave Reid’s picture

Status: Needs work » Needs review
FileSize
3.08 KB

Tests only this time. This should pass.

  • Dave Reid committed 52ff3ad on 7.x-1.x
    Issue #1838640 by Dave Reid: Added tests to confirm...
Dave Reid’s picture

Status: Needs review » Fixed

Committed the tests in #49 to 7.x-1.x.

  • Dave Reid committed ef46517 on 7.x-3.x
    Issue #1838640 by Dave Reid: Added tests to confirm...
dgtlmoon’s picture

Nice work! thanks!

Dave Reid’s picture

Version: 7.x-1.x-dev » 7.x-2.x-dev
Status: Fixed » Patch (to be ported)

Fix needs to be applied to the 7.x-2.x branch if we're going to keep it open.

Devin Carlson’s picture

Version: 7.x-2.x-dev » 7.x-3.x-dev
Status: Patch (to be ported) » Fixed

Status: Fixed » Closed (fixed)

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