How to store node content in Drupal

Source: Internet
Author: User
Tags drupal

You will be surprised when you look at the node table in Drupal. that is because you can not find the content field which is used to store the content. in fact, Drupal uses field API to store the content. frankly speaking, this is a good design and one of Drupal's advantages. you can understand node as the base table and it can be extended in other tables.

In the following, I will use Blog module to make in-depth explanation.

1. Declare blog node type

[Html]
Function blog_node_info (){
Return array (
'Blog '=> array (
'Name' => t ('blog entry '),
'Base' => 'blog ',
'Description' => t ('use for multi-user blogs. Every user gets a personal blog .'),
)
);
}
From Node API, we can know that hook_node_info is to define module-provided node types. the base key-value entry in the array means that it will use blog prefix hook at first priority for the node operation callback.
2. Attach the body field to blog node type

[Html]
Function blog_install (){
// Ensure the blog node type is available.
Node_types_rebuild ();
$ Types = node_type_get_types ();
Node_add_body_field ($ types ['blog ']);
}
Node_types_rebuild method's task is to collect the data from the modules which implements hook_node_info, then save the data into table node_type and put the data into cache for instant usage.
For function node_add_body_field, it is necessary to look its function body.

[Html]
Function node_add_body_field ($ type, $ label = 'body '){
// Add or remove the body field, as needed.
$ Field = field_info_field ('body ');
$ Instance = field_info_instance ('node', 'body', $ type-> type );
Return $ instance;
}

From the code statements, they are apparently self-explaining. it loads the field body's information and create an instance, then attach the instance to blog node type. I will need e field API and Node type UI (filed and node rendering) next time to make it as complete story.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.