首頁 php教程 php手册 How to store node content in Drupal

How to store node content in Drupal

Jun 13, 2016 am 10:53 AM
content drupal node store

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.

本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

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

AI Clothes Remover

AI Clothes Remover

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

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

AI Hentai Generator

AI Hentai Generator

免費產生 AI 無盡。

熱門文章

R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
3 週前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳圖形設置
3 週前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.如果您聽不到任何人,如何修復音頻
3 週前 By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25:如何解鎖Myrise中的所有內容
4 週前 By 尊渡假赌尊渡假赌尊渡假赌

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

SublimeText3 Mac版

SublimeText3 Mac版

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

nvm 怎麼刪除node nvm 怎麼刪除node Dec 29, 2022 am 10:07 AM

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

node專案中如何使用express來處理檔案的上傳 node專案中如何使用express來處理檔案的上傳 Mar 28, 2023 pm 07:28 PM

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

深入淺析Node的進程管理工具'pm2” 深入淺析Node的進程管理工具'pm2” Apr 03, 2023 pm 06:02 PM

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

Pi Node教學:什麼是Pi節點?如何安裝和設定Pi Node? Pi Node教學:什麼是Pi節點?如何安裝和設定Pi Node? Mar 05, 2025 pm 05:57 PM

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

聊聊用pkg將Node.js專案打包為執行檔的方法 聊聊用pkg將Node.js專案打包為執行檔的方法 Dec 02, 2022 pm 09:06 PM

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

微軟商店打不開顯示\'很抱歉!出錯了,但我們做對了\'-【詳細解決方法】 微軟商店打不開顯示\'很抱歉!出錯了,但我們做對了\'-【詳細解決方法】 Mar 27, 2024 pm 01:21 PM

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

npm node gyp失敗怎麼辦 npm node gyp失敗怎麼辦 Dec 29, 2022 pm 02:42 PM

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怎麼實作? 什麼是單一登入系統?用nodejs怎麼實作? Feb 24, 2023 pm 07:33 PM

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

See all articles