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项目打包为可执行文件的方法,希望对大家有所帮助!

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

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

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