Hey folks, I am trying to create a new node type in a module I am writing. I was originally planning to do this through the UI, but as I can not figure out how to get any information from the node (I tried 'global $node;') in any php snippets on the page, I have to write my own hook_view().

Any way, I have been trying to add fields to my new node type, I have followed the "node_example" which does not appear to work correctly, and piece together what information I can find to achieve this and I am drawing a blank. I think my hook_node_type_insert() is running, or at least the body field is getting added with the title I have set, but I cannot get my other fields to be added. It appears that I need to create the field with field_create_field(), then set up some form of instance with field_create_instance. Are there any good (working) example of how these functions should work together so I can add an 'address' field to my restaurant node type?

Any information would be thankfully received at this point, I have been struggling with this for about 2 days now.

Anthony

Comments

nevets’s picture

My guess is you do not need to create a content type in code. The solution though lies with the context of $node and how you want to use it.

toftat’s picture

My wish is that I don't need a new module to define my content type, however, without having any knowledge of the node, there is not much I can do. I want to add searches to the page. From the UI my idea was to use fields that are defaulted to the php filter and a lump of code. I would then disable editing of the field with the field permissions module.

I guess I need to dig around a bit more and see what I can find out from the page as it displays.

nevets’s picture

Not sure what you are searching for but have you looked at the views module?

toftat’s picture

I did look at the views module, but I could not figure out how to make that do what I want to do:

1. The current node has information attached to it that doesn't change often and is only valid to have 1 version of (ie address)
2. The current node has multiple instances of other information attached to it that is of different types (different report types and blog posts)

I solve requirement 1 by using the node (either defined through the UI or as I suspect is necessary defined in code) I solve requirement 2 by using taxonomy terms, the Rules module is configured to generate the appropriate term on node creation. The issue lies in getting the php to execute when I look at the node created for req. 1.

Looking at the available variables using dprint_r($GLOBALS) it does not appear that I have any indication of the node I am looking at other than the from the $GLOBALS[_SERVER][REQUEST_URI] which may or may not have the nid in it (it does for non-redirected nodes, not sure about pretty URLS)

So I am back to needing a programmatic node type with fields added.