首页 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.能量晶体解释及其做什么(黄色晶体)
4 周前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳图形设置
4 周前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.如果您听不到任何人,如何修复音频
4 周前 By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25:如何解锁Myrise中的所有内容
1 个月前 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项目打包为可执行文件的方法,希望对大家有所帮助!

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”版本即可。

微软商店打不开显示\'很抱歉!出错了,但我们做对了\'-【详细解决方法】 微软商店打不开显示\'很抱歉!出错了,但我们做对了\'-【详细解决方法】 Mar 27, 2024 pm 01:21 PM

有用户想要在微软商店查找自己喜欢的应用并下载安装,但是发现微软商店打不开了,同时还提示"很抱歉!出错了,但我们做对了",那么我们应该如何解决,才能让微软商店恢复正常运行并使用呢?下面小编整理了两种方法,希望可以很好的帮到你!方法一可以按下Win+R→输入cmd然后按住ctrl+shift→点击确定(弹出UAC后点击是)然后弹出cmd窗口(管理员模式)然后复制粘贴以下内容:netshwinsockresetnetshintipresetipconfig/releaseipconfig/renewi

什么是单点登录系统?用nodejs怎么实现? 什么是单点登录系统?用nodejs怎么实现? Feb 24, 2023 pm 07:33 PM

什么是单点登录系统?用nodejs怎么实现?下面本篇文章给大家介绍一下使用node实现单点登录系统的方法,希望对大家有所帮助!

See all articles