I'm creating a module that deals with stories and chapters (as content types). I used the existing "story" content type and added a new one for "chapter". In order to get my hook_access to run, though, I found that the value for the "module" column in the {node_type} table must be the name of my module instead of "node", so I changed it for those two content types. Now those types don't show in admin/content/types or on the create content page. I think it's an issue with the menu table(s)... but I'm not sure exactly what the problem is or how to correct it. Any thoughts?

Comments

nevets’s picture

You need to reevaluate how you are doing things, changing the module column from "node" is going to cause grief.

What is your actual goal (need for a custom module)?

extexan’s picture

I started out with my module creating it's own node types, but "Story" and "Chapter" are the terms I want my visitors to see when creating stories (and chapters). I couldn't have two story content types, so at the very least I needed to re-use that one even if my module was creating "chapter" type. I also re-evaluated using CCK and Views (instead of reinventing all those wheels in my module).

So what I was trying to do when I changed to value of module in {node_type} is to get my hook_access function to execute. Access to stories, or rather, chapters, is based on the value of "can_view" field at the story level (values are "Only me", "Me and my friends", "All registered members", and "Anyone"). Btw, I'm using the books module to handle the structure of story with chapters under it, so story is the top level of the hierarchy. So my hook_access function needs to read the can_view value for the "story" node for the chapter being viewed (or about to be viewed) and if the user doesn't fit the can_view option, it should not allow access.

Is there another (better?) way to do that other than using hook_access? And/or how do I get hook_access to execute if I don't change the value of module in {node_type}?

It's never too late to have a happy childhood. ;-)

extexan’s picture

To save time, I just changed the value of module using phpMyAdmin (since there wasn't a way to do it in Drupal). If I want to use "story" content type for my own purposes, should I delete the default one that is created during Drupal install, and create a new one with my module name?

It's never too late to have a happy childhood. ;-)

nevets’s picture

Content types have two name, the machine name and the one people see. You can edit both (ie change for existing content types).

extexan’s picture

I know I can change the names (name and type). That's not the problem. I needed to change the module name in the {node_type} table - from "node" to "my_module". It's the only way I could see to get my module's hook_access to execute. That's when I ran into the problem of those content types not showing up on various pages in Drupal (though they did still show in Admin Menu module - I suspect that's because that module reads {node_type} directly instead of relying on {menu_links}).

In my prev post, I posed the question about maybe deleting the Story content type and adding it back with "my_module" as the module name, but now I realize that even when creating a content type, there's no place to enter the module name. So all content types that get created on that page automatically have "node" as the module, and content types created programmatically by custom modules will have the module name match the defining module - am I correct on that?

So back to the original problem... how do I hook into access permissions for a node when it can't be specified by user permissions or roles or anything like that. My module has to potentially read a parent node to determine accessibility of the current node.

It's never too late to have a happy childhood. ;-)

extexan’s picture

Does anyone have an answer re: my access permissions problem? (pls read the last post before this one.)

It's never too late to have a happy childhood. ;-)

nevets’s picture

Look at one of the existing access modules.

extexan’s picture

@nevets... look at what specifically? If you mean modules specifically designed to allow my module to hook into node access, I don't know what those would be. If you mean I should search for other modules that are doing node access logic (and this is what I think you mean), I've done that. I can't use the usual access permissions because access in this particular case depends on a "parent" node. Here's a more detailed example.

User A creates:

My Story (content type "story")
- Chapter 1 (content type "chapter" - child of "My Story")
- Chapter 2 (content type "chapter" - child of "My Story")
... so on for as many chapters as needed ...

User B tries to view Chapter 1:
- my module needs to find the "can_view" field (added to content type "story" via CCK) for the "My Story" node (parent of Chapter 1). If the value of that field allows User B to access this story (and its chapters), then access is granted. Otherwise, it is denied.

The problem, as stated previously, was that with the module field set to "node" for content type "chapter" (and "story"), my hook_access() function is not executed. If you recall, I had changed the module field value in phpMyAdmin, thinking that it might be bad to delete the existing content type of "story". But even when I DID delete that content type and added it back in, I found that there's no place to enter the value for the module field - it always defaults to "node".

So, is this the solution?...
a) Delete "story" content type (and any others that don't pertain to my module).
b) Have my module create its own content types of "story" and "chapter", which will ensure that the module field will contain the name of my module and, thus, the hook_access function will be executed.

It's never too late to have a happy childhood. ;-)