开发者

How to hook_load a CCK custom content type in a MENU_CALLBACK drupal

开发者 https://www.devze.com 2023-03-26 09:41 出处:网络
This is for the DRUPAL ninjas: I am creating a menu_hook for my custom module called testmodule; I want to call a MENU_CALLBACK and return a loaded CCK object of a custom content type I created call

This is for the DRUPAL ninjas:

  1. I am creating a menu_hook for my custom module called testmodule;
  2. I want to call a MENU_CALLBACK and return a loaded CCK object of a custom content type I created called "VideoNodes"

example:

 $items['save_video_data/%my_custom_cck_type/%'] = array(
        'type' =>开发者_运维知识库; MENU_CALLBACK,
        'page callback' => 'save_data_to_db',
        'access arguments' => array('Save Data to my_custom_cck_type'),
        'page arguments' => array(2),
        'type' => MENU_CALLBACK,
        'title' => 'Save a Data!'
        );

Now, with the above code, my understanding is that I am telling drupal to load my_custom_cck_type and use the array(2) position (my argument) as the id field of the node to find it in the database.

I also understand that, I am going to need to create a my_custom_cck_type_load() function.

QUESTION:

What shoudl be in my_custom_cck_type_load()?? How shall I grab all of the custom fields associated with the CCK type into the returned object? Or does drupal do this for me?


I'll use node_load as an example for this. Out of the box Drupal's menu system will load nodes at paths like.

node/1/view
node/2/view
node/3/view

(note: the "/view" part of the path is often hidden because it's the default tab)

The menu item setup to do this looks something like:

$items['node/%node/view'] = array(
  'type' => MENU_DEFAULT_LOCAL_TASK,
  'title' => 'blabla',
  'page callback' => 'node_view',
  'page arguments' => array(1)
  /* more stuff */
);

In the real path the %node is replaced by a number, the NID of the node. This will cause menu to fire node_load using that number as the argument. We're also using %node as the page argument for the node_view callback. The argument that callback receives will be the fully loaded node object.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号