Both restws and panels takes over /node/%, meaning a node displayed with panels can't also be retrieved as /node/%.json

Is there a way to solve that within this module, or would one need to go with services?

Comments

klausi’s picture

It is not documented and matured yet, but we have planned a bit for such cases. You can use hook_restws_resource_alter() and set something like this

$info['node']['menu path'] = 'restws/node';

Caution: If you retrieve nodes from that path and they contain reference links to other nodes, the path will probably not be correct (i.e. will be "/node/1.json"). If that does not matter to you, you shouldn't have a problem. Anyway, this has not been tested yet so I would appreciate your feedback :-)

fago’s picture

hm, #1 is a possible workaround but it basically disables restws for the path node/%. It would be great to find ways to work even if panels is already altering the menu. Maybe just shuffling with module weights would work?

Dinesh Kumar Sarangapani’s picture

I have tested as per #1, but it doesn't seems to work, as the page call back 'restws_page_callback' uses arg(1) to get the resource id, having a altered menu path via code may have the id in different position. say restws/node/1.json returns arg(1) as node, which leads to 404 NOT FOUND

Dinesh Kumar Sarangapani’s picture

Modified the function as below

/**
 * Menu page callback.
 */
function restws_page_callback($resource, $page_callback = NULL) {
  $redirect_url = $_GET['q'];
  $redirect_url = explode('/',$redirect_url);
  $id_arg_format = $redirect_url[count($redirect_url)-1];
  $id_arg_format = explode('.',$id_arg_format);
  $id_arg = $id_arg_format[0];
  $format = FALSE;
  
  // Check for a appended .format string.
  if ( isset($id_arg_format[1]) && count($id_arg_format) > 1) {
    $id = $id_arg;
    $format_name = $id_arg_format[1];
    $format = restws_format($format_name);
  }
  else {....

Works for me...

Dinesh Kumar Sarangapani’s picture

As per #2 Even after shuffling weight of the module one has to override another..

Dinesh Kumar Sarangapani’s picture

Status: Active » Needs review
seanburlington’s picture

@klausi

This almost works

$info['node']['menu path'] = 'restws/node';

But moves the arg so that this no longer works

function restws_page_callback($resource, $page_callback = NULL) {
  $id_arg = arg(1);
  $format = FALSE;

I can hack it so that the arg() position is adjusted, then it seems OK

seanburlington’s picture

Title: Restws and Panels path conflict » Restws and panels / page manager path conflict
StatusFileSize
new672 bytes

OK I've looked into this some more

It seems that restws alters the menu - but if the requests isn't a rest-ish one then it tries to pass the call back to what it was (which is the original node handler)

page manager sets a high weight for itself so it is called after restws, sees the menu is changed and goes off in a sulk (quietly aborts the menu alter)

So if we make restws have a higher weight it is called after page manager and the sequence is

page manager sees the original node menu and is happy, restws alters the menu again - but it's callback falls over to what it was before restws altered it - this now falls back to the page manager hook :-)

The attached patch alters the weight of restws to be 1 greater than the page_manager module weight which is 99

seanburlington’s picture

NB - this patch adds an install / update hook

apply the patch and the run updb if you have already installed the module

klausi’s picture

klausi’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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