1

I am using Drupal 6. I have an external database that I need to somehow turn into nodes so that our Drupal site can display the content and search the content with Solr. I currently have a module which displays pages and queries the database directly each time these pages are viewed. This is not an optimal solution because these pages are not found when a user uses our search.

I know that I can iterate through the database items, create a $node object and use node_save() to create nodes.

1) Can I set a specific NID such as $node->nid = 9999999 . $some_database_key so that I know these nodes can be referenced later for updating?

I could not get this to work, but I did figure out this solution: I created a database table for my module similar to the one in the node_example module. Using this and a custom content type, I could create nodes. I could not get it to work properly until I used

$node = node_submit($node);

prior to calling

node_save($node);

2) How do I create menu items for these new nodes?

Solution

$link = array();
$link['menu_name'] = 'custom_menu'; // Fill out your menu name or just use navigation
$link['link_title'] = 'Title Here'; // What appears in the menu link
$link['link_path'] = 'node/' . $node->nid; // Or you can use a path alias as well
$link['plid'] = 12; // Optional - if you want it to nest under an item you'll need its mlid (menu id)
menu_link_save($link);

See: http://api.drupal.org/api/drupal/includes--menu.inc/function/menu_link_save/6

3) How do I create aliases for these nodes such as node/856 goes to programs/some-program-type/some-program-title

SOLUTION Similar to the menu solution above, you can use

path_set_alias('node/' . $node->nid, 'path/alias/here');

Thanks for any suggestions!

1

I understand that you have some external database, and your nodes are in relation with some entities from there. You need node 'downloading' some content from other database; for compatibility with Solr.

1) Instead 'hacking' node number, I think you should use create node type for it. Beside distinguishing downloaded nodes for others; you can create CCK field for storing external database id; and setting content edition permission that nobody can edit it.

2) In your custom module you need to implement hook_blocks to put in the menu content that you need.

3) With pathauto module you can simply create automatic path. If you create special content type out of the box pathauto functionality should be enough.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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