1

I'm looking for something to help me understand drupal core and its functions. I've gotten a hang of writing modules, and I've found plenty of resources, such as books and blog posts. But I'm still stumbling when I find I'm needing to manipulate basic core functions such as creating nodes or manipulating users.

Of course, there is the documentation of each function, but it doesn't tell you much beyond what that function does.

For instance, I wanted to create some nodes automatically in my module. I know about node_save, but I didn't know what fields I had to set in order for my new node to be saved properly. The documentation says that node_save saves a node to the database -- so it doesn't tell you anything more than what the function name already says. My node creation in my module is not working. Then I hear somewhere along the about about node_save_prepare for creating new nodes -- maybe I need to do that? But its documentation says that it prepares a node for editing. So I look in my module dev resources, and they talk about the various hooks... which assume some basic understanding of core functionality. So after some more hacking and trial and error, I get my nodes created... with the title only. Do I set the body with $node->body = "blah" or $node->body[0]['und']['value'] = "blah" (and what is all that stuff, anyway)?

Of course I can source dive, but that doesn't really tell you any more about the right way to do things. So I'm looking for something comprehensive about "how do to things". Does there presently exist such a resource?

One book I have read is Pro Drupal 7 Development, and while it's a great resource for understanding hooks, it doesn't go into core functions in a comprehensive, foundational way.

Please note: It's okay to answer "No such single comprehensive resource exists" or "You'll have to piece it together from multiple sources." If that's the reality of the situation, I want to know that rather than continuing my holy grail quest. I'm not looking to be pointed to more piecemeal resources. I'm asking if there's one comprehensive one for understanding core api functions.

2 Answers 2

1

The Examples module is a good way to see "how to do things". Another useful tool is grep - you can download all of contrib, and search for examples where other developers have implemented the hook or function that interests you. You can "upgrade" to ack for more powerful searching. The book "Pro Drupal Development" used to be a good resource, but sadly the 7.x edition is rubbish.

1
  • Well then... source diving it is!
    – user1359
    Sep 2, 2011 at 16:27
0

I would highly recommend two books.

Pro Drupal Development is a must have, though the D7 version isn't as good as the previous versions.

Drupal 7 Module Development is also a good reference.

The other thing you can do is find modules that you are familiar with (ie, those that you have been using) that do similar tasks and look at the source code. drush hooks can also be enlightening.

3
  • I've got Pro Drupal 7 Development, I've read it, and it doesn't really talk about core functions in a comprehensive way. Does the D6 version go into it? I don't need any more explanation or reference for hooks; I need to understand the core api.
    – user1359
    Sep 2, 2011 at 16:13
  • The "core API" really is just an implementation of the hook system. You need to find a module that does something similar. If you want to create nodes via code, then find a module that does this. There are a bunch of import modules, but I think many now use the Migrate module. Or, post specific inquiries here.
    – mpdonadio
    Sep 2, 2011 at 16:30
  • In my node-creating module, I found a blog post that showed how to create nodes. It included this $node->type = "page"; for the type specification. So I go and do $node->type = "My Content Type";, and I get content with no type. After some trial and error, I figure out that it wants the machine name of the content type. The problem is when you look at code, there's no indication of what they're doing or why they're doing it. This is why people write books and guides ("When creating a node, specify the machine name of the content type..."), which is what I'm looking for.
    – user1359
    Sep 2, 2011 at 18:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.