How to store node content in 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 advantage. 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 explore field API and Node type UI (filed and node rendering) next time to make it as complete story.

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

熱門話題

nvm刪除node的方法:1、下載「nvm-setup.zip」並將其安裝在C碟;2、設定環境變量,並透過「nvm -v」指令查看版本號;3、使用「nvm install」指令安裝node;4、透過「nvm uninstall」指令刪除已安裝的node即可。

怎麼處理文件上傳?以下這篇文章為大家介紹一下node專案中如何使用express來處理文件的上傳,希望對大家有幫助!

這篇文章跟大家分享Node的進程管理工具“pm2”,聊聊為什麼需要pm2、安裝和使用pm2的方法,希望對大家有幫助!

PiNetwork節點詳解及安裝指南本文將詳細介紹PiNetwork生態系統中的關鍵角色——Pi節點,並提供安裝和配置的完整步驟。 Pi節點在PiNetwork區塊鏈測試網推出後,成為眾多先鋒積極參與測試的重要環節,為即將到來的主網發布做準備。如果您還不了解PiNetwork,請參考Pi幣是什麼?上市價格多少? Pi用途、挖礦及安全性分析。什麼是PiNetwork? PiNetwork項目始於2019年,擁有其專屬加密貨幣Pi幣。該項目旨在創建一個人人可參與

如何用pkg打包nodejs可執行檔?以下這篇文章跟大家介紹一下使用pkg將Node專案打包為執行檔的方法,希望對大家有幫助!

有用戶想要在微軟商店尋找自己喜歡的應用程式並下載安裝,但是發現微軟商店打不開了,同時還提示"很抱歉!出錯了,但我們做對了",那麼我們應該如何解決,才能讓微軟商店恢復正常運作並使用呢?下面小編整理了兩種方法,希望可以很好的幫助你!方法一可以按Win+R→輸入cmd然後按住ctrl+shift→點選確定(彈出UAC後點選是)然後彈出cmd視窗(管理員模式)然後複製貼上以下內容:netshwinsockresetnetshintipresetipconfig/releaseipconfig/renewi

npm node gyp失敗是因為“node-gyp.js”跟“Node.js”版本不匹配,其解決辦法:1、透過“npm cache clean -f”清除node快取;2、透過“npm install -g n”安裝n模組;3、透過「n v12.21.0」指令安裝「node v12.21.0」版本即可。

什麼是單一登入系統?用nodejs怎麼實作?以下這篇文章為大家介紹一下使用node實作單一登入系統的方法,希望對大家有幫助!
