Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Apress.Pro.Drupal.7.Development.3rd.Edition.Dec.2010.pdf
Скачиваний:
63
Добавлен:
14.03.2016
Размер:
12.64 Mб
Скачать

CHAPTER 7 WORKING WITH NODES

Figure 7-4. Simple theme of job post node

Figure 7-5. The sponsor is not added when the node is shown in teaser view.

Manipulating Nodes That Are Not Our Type with hook_node_xxxxx()

The preceding hooks are invoked only based on the base key of the module’s hook_node_info() implementation. When Drupal sees a blog node type, blog_load() is called. What if you want to add some information to every node, regardless of its type? The hooks we’ve reviewed so far aren’t going to cut it; for that, we need an exceptionally powerful set of hooks.

153

CHAPTER 7 WORKING WITH NODES

The node_xxxx hooks create an opportunity for modules to react to the different operations during the life cycle of any node. The node_xxxx hooks are usually called by node.module just after the node- type–specific callback is invoked. Here’s a list of the primary node_xxxx hook functions:

hook_node_insert($node): Responds to creation of a new node.

hook_node_load($node, $types): Acts on nodes being loaded from the database. $nodes is a keyed array of nodes being loaded where the key is the node ID, $types is an array of node types being loaded.

hook_node_update($node): Responds to updates to a node.

hook_node_delete($node): Responds to node deletion.

hook_node_view($node, $view_mode): Acts on a node that is being rendered where $view_mode defines what mode the node is being displayed in—e.g., full or teaser.

hook_node_prepare($node): Acts on a node that is about to be shown in the add/edit form.

hook_node_presave($node): Acts on a node that is being inserted or updated.

hook_node_access($node, $op, $account): Controls access to a node where $op is the type of operation being performed (e.g., insert, update, view, delete) and $account is the user account of the person performing the operation.

hook_node_grants_alter(&$grants, $account, $op): Alters user access grants when trying to view, edit, or delete a node.

The order in which hooks are fired when displaying a node page such as

http://example.com/?q=node/3 is shown in Figure 7-6.

154

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]