I need to get some node via ajax, but when trying to access node through custom hook_menu callback I got 404 (RH setting: page not found).

Let's say I have hook_menu item:

$items['ajax/%node/%ctools_js'] = array(
    'title' => 'Node title',
    'title arguments' => array(1),
    'page callback' => 'custom_page_callback',
    'page arguments' => array(1, 2),
    'access callback' => TRUE,
    'type' => MENU_CALLBACK,
  );

In my custom_page_callback I'm using node_view(%node_path_argument) and ajax commands to render and display content.

'access callback' => TRUE allows me to see even unpublished content but not content hidden (i.e. page not found) by RH module.

Is this normal behavior? I thought that RH module blocks access only when visiting node/x path.

Comments

krystianbuczak created an issue. See original summary.

olofbokedal’s picture

Category: Support request » Bug report

That is not the intended behavior, so it's definitely a bug.

Probably some logic within the implementation of hook_node_view().

hgoto’s picture

Status: Active » Needs review
StatusFileSize
new2.01 KB

I believe, in order to fix this, it's better to implement hook_menu_alter() and a custom page callback which wraps the original callback. Because adjusting rh_node_node_view() so that the alteration would be applied only to the default page /node/%node is a little tricky.

This is the same approach as in the patch #2711941-1: Add support for Taxonomy Term feeds. I tried making a patch for this.

olofbokedal’s picture

There's perhaps a more suitable issue for the patch above. I won't close this issue though, better to keep things open until solved in some way.

hgoto’s picture

@olofjohansson thank you for your response! I see. I'll try to contribute in the issue #2486101: Trigger RH regardless of page callback later.

rob230’s picture

This is a bug in the Drupal 8 version of the module as well.

If I set a particular content type to 404, then my own custom route like this also 404s:

my_module.my_route:
  path: '/my-module/{node}'
  defaults:
    _controller: '\Drupal\my_module\Controller\MyModule::myAjaxFunction'
  options:
    parameters:
      node:
        type: entity:node

This route (and any route using the node object of this type) will 404 unless rabbit_hole settings for that content type are changed.

The expected behaviour is the rabbit_hole module would only affect the path that displays the node, e.g. node/{node}.

imyaro’s picture

Status: Needs review » Needs work

I don't think that patch in comment #3 is a good decision, because in this case nodes in the listings (in "teaser"-type view modes) will be affected too. It is not the case that Rabbit Hole module has to handle

japerry’s picture

Status: Needs work » Closed (outdated)

Page Manager 8.x-1.x is no longer supported, closing.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.