Skip navigation
Help

node.api.php

  1. drupal
    1. 7 drupal/modules/node/node.api.php

Hooks provided by the Node module.

Functions & methods

NameDescription
hook_deleteRespond to node deletion.
hook_formDisplay a node editing form.
hook_insertRespond to creation of a new node.
hook_loadAct on nodes being loaded from the database.
hook_node_accessControl access to a node.
hook_node_access_recordsSet permissions for a node to be written to the database.
hook_node_access_records_alterAlter permissions for a node before it is written to the database.
hook_node_deleteRespond to node deletion.
hook_node_grantsInform the node access system what permissions the user has.
hook_node_grants_alterAlter user access rules when trying to view, edit or delete a node.
hook_node_infoDefine module-provided node types.
hook_node_insertRespond to creation of a new node.
hook_node_loadAct on nodes being loaded from the database.
hook_node_operationsAdd mass node operations.
hook_node_prepareAct on a node object about to be shown on the add/edit form.
hook_node_presaveAct on a node being inserted or updated.
hook_node_revision_deleteRespond to deletion of a node revision.
hook_node_search_resultAct on a node being displayed as a search result.
hook_node_submitAct on a node after validated form values have been copied to it.
hook_node_type_deleteRespond to node type deletion.
hook_node_type_insertRespond to node type creation.
hook_node_type_updateRespond to node type updates.
hook_node_updateRespond to updates to a node.
hook_node_update_indexAct on a node being indexed for searching.
hook_node_validatePerform node validation before a node is created or updated.
hook_node_viewAct on a node that is being assembled before rendering.
hook_node_view_alterAlter the results of node_view().
hook_prepareAct on a node object about to be shown on the add/edit form.
hook_rankingProvide additional methods of scoring for core search results for nodes.
hook_updateRespond to updates to a node.
hook_validatePerform node validation before a node is created or updated.
hook_viewDisplay a node.

File

drupal/modules/node/node.api.php
View source
  1. <?php
  2. /**
  3. * @file
  4. * Hooks provided by the Node module.
  5. */
  6. /**
  7. * @defgroup node_api_hooks Node API Hooks
  8. * @{
  9. * Functions to define and modify content types.
  10. *
  11. * Each content type is maintained by a primary module, which is either
  12. * node.module (for content types created in the user interface) or the
  13. * module that implements hook_node_info() to define the content type.
  14. *
  15. * During node operations (create, update, view, delete, etc.), there are
  16. * several sets of hooks that get invoked to allow modules to modify the base
  17. * node operation:
  18. * - Node-type-specific hooks: These hooks are only invoked on the primary
  19. * module, using the "base" return component of hook_node_info() as the
  20. * function prefix. For example, poll.module defines the base for the Poll
  21. * content type as "poll", so during creation of a poll node, hook_insert() is
  22. * only invoked by calling poll_insert().
  23. * - All-module hooks: This set of hooks is invoked on all implementing
  24. * modules, to allow other modules to modify what the primary node module is
  25. * doing. For example, hook_node_insert() is invoked on all modules when
  26. * creating a poll node.
  27. * - Field hooks: Hooks related to the fields attached to the node. These are
  28. * invoked from the field operations functions described below, and can be
  29. * either field-type-specific or all-module hooks.
  30. * - Entity hooks: Generic hooks for "entity" operations. These are always
  31. * invoked on all modules.
  32. *
  33. * Here is a list of the node and entity hooks that are invoked, field
  34. * operations, and other steps that take place during node operations:
  35. * - Creating a new node (calling node_save() on a new node):
  36. * - field_attach_presave()
  37. * - hook_node_presave() (all)
  38. * - hook_entity_presave() (all)
  39. * - Node and revision records are written to the database
  40. * - hook_insert() (node-type-specific)
  41. * - field_attach_insert()
  42. * - hook_node_insert() (all)
  43. * - hook_entity_insert() (all)
  44. * - hook_node_access_records() (all)
  45. * - hook_node_access_records_alter() (all)
  46. * - Updating an existing node (calling node_save() on an existing node):
  47. * - field_attach_presave()
  48. * - hook_node_presave() (all)
  49. * - hook_entity_presave() (all)
  50. * - Node and revision records are written to the database
  51. * - hook_update() (node-type-specific)
  52. * - field_attach_update()
  53. * - hook_node_update() (all)
  54. * - hook_entity_update() (all)
  55. * - hook_node_access_records() (all)
  56. * - hook_node_access_records_alter() (all)
  57. * - Loading a node (calling node_load(), node_load_multiple(), or
  58. * entity_load() with $entity_type of 'node'):
  59. * - Node and revision information is read from database.
  60. * - hook_load() (node-type-specific)
  61. * - field_attach_load_revision() and field_attach_load()
  62. * - hook_entity_load() (all)
  63. * - hook_node_load() (all)
  64. * - Viewing a single node (calling node_view() - note that the input to
  65. * node_view() is a loaded node, so the Loading steps above are already
  66. * done):
  67. * - hook_view() (node-type-specific)
  68. * - field_attach_prepare_view()
  69. * - hook_entity_prepare_view() (all)
  70. * - field_attach_view()
  71. * - hook_node_view() (all)
  72. * - hook_entity_view() (all)
  73. * - hook_node_view_alter() (all)
  74. * - hook_entity_view_alter() (all)
  75. * - Viewing multiple nodes (calling node_view_multiple() - note that the input
  76. * to node_view_multiple() is a set of loaded nodes, so the Loading steps
  77. * above are already done):
  78. * - field_attach_prepare_view()
  79. * - hook_entity_prepare_view() (all)
  80. * - hook_view() (node-type-specific)
  81. * - field_attach_view()
  82. * - hook_node_view() (all)
  83. * - hook_entity_view() (all)
  84. * - hook_node_view_alter() (all)
  85. * - hook_entity_view_alter() (all)
  86. * - Deleting a node (calling node_delete() or node_delete_multiple()):
  87. * - Node is loaded (see Loading section above)
  88. * - hook_delete() (node-type-specific)
  89. * - hook_node_delete() (all)
  90. * - hook_entity_delete() (all)
  91. * - field_attach_delete()
  92. * - Node and revision information are deleted from database
  93. * - Deleting a node revision (calling node_revision_delete()):
  94. * - Node is loaded (see Loading section above)
  95. * - Revision information is deleted from database
  96. * - hook_node_revision_delete() (all)
  97. * - field_attach_delete_revision()
  98. * - Preparing a node for editing (calling node_form() - note that if it's
  99. * an existing node, it will already be loaded; see the Loading section
  100. * above):
  101. * - hook_prepare() (node-type-specific)
  102. * - hook_node_prepare() (all)
  103. * - hook_form() (node-type-specific)
  104. * - field_attach_form()
  105. * - Validating a node during editing form submit (calling
  106. * node_form_validate()):
  107. * - hook_validate() (node-type-specific)
  108. * - hook_node_validate() (all)
  109. * - field_attach_form_validate()
  110. * - Searching (calling node_search_execute()):
  111. * - hook_ranking() (all)
  112. * - Query is executed to find matching nodes
  113. * - Resulting node is loaded (see Loading section above)
  114. * - Resulting node is prepared for viewing (see Viewing a single node above)
  115. * - comment_node_update_index() is called.
  116. * - hook_node_search_result() (all)
  117. * - Search indexing (calling node_update_index()):
  118. * - Node is loaded (see Loading section above)
  119. * - Node is prepared for viewing (see Viewing a single node above)
  120. * - hook_node_update_index() (all)
  121. * @}
  122. */
  123. /**
  124. * @addtogroup hooks
  125. * @{
  126. */
  127. /**
  128. * Inform the node access system what permissions the user has.
  129. *
  130. * This hook is for implementation by node access modules. In this hook,
  131. * the module grants a user different "grant IDs" within one or more
  132. * "realms". In hook_node_access_records(), the realms and grant IDs are
  133. * associated with permission to view, edit, and delete individual nodes.
  134. *
  135. * The realms and grant IDs can be arbitrarily defined by your node access
  136. * module; it is common to use role IDs as grant IDs, but that is not
  137. * required. Your module could instead maintain its own list of users, where
  138. * each list has an ID. In that case, the return value of this hook would be
  139. * an array of the list IDs that this user is a member of.
  140. *
  141. * A node access module may implement as many realms as necessary to
  142. * properly define the access privileges for the nodes. Note that the system
  143. * makes no distinction between published and unpublished nodes. It is the
  144. * module's responsibility to provide appropriate realms to limit access to
  145. * unpublished content.
  146. *
  147. * Node access records are stored in the {node_access} table and define which
  148. * grants are required to access a node. There is a special case for the view
  149. * operation -- a record with node ID 0 corresponds to a "view all" grant for
  150. * the realm and grant ID of that record. If there are no node access modules
  151. * enabled, the core node module adds a node ID 0 record for realm 'all'. Node
  152. * access modules can also grant "view all" permission on their custom realms;
  153. * for example, a module could create a record in {node_access} with:
  154. * @code
  155. * $record = array(
  156. * 'nid' => 0,
  157. * 'gid' => 888,
  158. * 'realm' => 'example_realm',
  159. * 'grant_view' => 1,
  160. * 'grant_update' => 0,
  161. * 'grant_delete' => 0,
  162. * );
  163. * drupal_write_record('node_access', $record);
  164. * @endcode
  165. * And then in its hook_node_grants() implementation, it would need to return:
  166. * @code
  167. * if ($op == 'view') {
  168. * $grants['example_realm'] = array(888);
  169. * }
  170. * @endcode
  171. * If you decide to do this, be aware that the node_access_rebuild() function
  172. * will erase any node ID 0 entry when it is called, so you will need to make
  173. * sure to restore your {node_access} record after node_access_rebuild() is
  174. * called.
  175. *
  176. * @see node_access_view_all_nodes()
  177. * @see node_access_rebuild()
  178. *
  179. * @param $account
  180. * The user object whose grants are requested.
  181. * @param $op
  182. * The node operation to be performed, such as "view", "update", or "delete".
  183. *
  184. * @return
  185. * An array whose keys are "realms" of grants, and whose values are arrays of
  186. * the grant IDs within this realm that this user is being granted.
  187. *
  188. * For a detailed example, see node_access_example.module.
  189. *
  190. * @ingroup node_access
  191. */
  192. function hook_node_grants($account, $op) {
  193. if (user_access('access private content', $account)) {
  194. $grants['example'] = array(1);
  195. }
  196. $grants['example_owner'] = array($account->uid);
  197. return $grants;
  198. }
  199. /**
  200. * Set permissions for a node to be written to the database.
  201. *
  202. * When a node is saved, a module implementing hook_node_access_records() will
  203. * be asked if it is interested in the access permissions for a node. If it is
  204. * interested, it must respond with an array of permissions arrays for that
  205. * node.
  206. *
  207. * Node access grants apply regardless of the published or unpublished status
  208. * of the node. Implementations must make sure not to grant access to
  209. * unpublished nodes if they don't want to change the standard access control
  210. * behavior. Your module may need to create a separate access realm to handle
  211. * access to unpublished nodes.
  212. *
  213. * Note that the grant values in the return value from your hook must be
  214. * integers and not boolean TRUE and FALSE.
  215. *
  216. * Each permissions item in the array is an array with the following elements:
  217. * - 'realm': The name of a realm that the module has defined in
  218. * hook_node_grants().
  219. * - 'gid': A 'grant ID' from hook_node_grants().
  220. * - 'grant_view': If set to 1 a user that has been identified as a member
  221. * of this gid within this realm can view this node. This should usually be
  222. * set to $node->status. Failure to do so may expose unpublished content
  223. * to some users.
  224. * - 'grant_update': If set to 1 a user that has been identified as a member
  225. * of this gid within this realm can edit this node.
  226. * - 'grant_delete': If set to 1 a user that has been identified as a member
  227. * of this gid within this realm can delete this node.
  228. * - 'priority': If multiple modules seek to set permissions on a node, the
  229. * realms that have the highest priority will win out, and realms with a lower
  230. * priority will not be written. If there is any doubt, it is best to
  231. * leave this 0.
  232. *
  233. *
  234. * When an implementation is interested in a node but want to deny access to
  235. * everyone, it may return a "deny all" grant:
  236. *
  237. * @code
  238. * $grants[] = array(
  239. * 'realm' => 'all',
  240. * 'gid' => 0,
  241. * 'grant_view' => 0,
  242. * 'grant_update' => 0,
  243. * 'grant_delete' => 0,
  244. * 'priority' => 1,
  245. * );
  246. * @endcode
  247. *
  248. * Setting the priority should cancel out other grants. In the case of a
  249. * conflict between modules, it is safer to use hook_node_access_records_alter()
  250. * to return only the deny grant.
  251. *
  252. * Note: a deny all grant is not written to the database; denies are implicit.
  253. *
  254. * @see node_access_write_grants()
  255. *
  256. * @param $node
  257. * The node that has just been saved.
  258. *
  259. * @return
  260. * An array of grants as defined above.
  261. *
  262. * @ingroup node_access
  263. */
  264. function hook_node_access_records($node) {
  265. // We only care about the node if it has been marked private. If not, it is
  266. // treated just like any other node and we completely ignore it.
  267. if ($node->private) {
  268. $grants = array();
  269. // Only published nodes should be viewable to all users. If we allow access
  270. // blindly here, then all users could view an unpublished node.
  271. if ($node->status) {
  272. $grants[] = array(
  273. 'realm' => 'example',
  274. 'gid' => 1,
  275. 'grant_view' => 1,
  276. 'grant_update' => 0,
  277. 'grant_delete' => 0,
  278. 'priority' => 0,
  279. );
  280. }
  281. // For the example_author array, the GID is equivalent to a UID, which
  282. // means there are many groups of just 1 user.
  283. // Note that an author can always view his or her nodes, even if they
  284. // have status unpublished.
  285. $grants[] = array(
  286. 'realm' => 'example_author',
  287. 'gid' => $node->uid,
  288. 'grant_view' => 1,
  289. 'grant_update' => 1,
  290. 'grant_delete' => 1,
  291. 'priority' => 0,
  292. );
  293. return $grants;
  294. }
  295. }
  296. /**
  297. * Alter permissions for a node before it is written to the database.
  298. *
  299. * Node access modules establish rules for user access to content. Node access
  300. * records are stored in the {node_access} table and define which permissions
  301. * are required to access a node. This hook is invoked after node access modules
  302. * returned their requirements via hook_node_access_records(); doing so allows
  303. * modules to modify the $grants array by reference before it is stored, so
  304. * custom or advanced business logic can be applied.
  305. *
  306. * @see hook_node_access_records()
  307. *
  308. * Upon viewing, editing or deleting a node, hook_node_grants() builds a
  309. * permissions array that is compared against the stored access records. The
  310. * user must have one or more matching permissions in order to complete the
  311. * requested operation.
  312. *
  313. * A module may deny all access to a node by setting $grants to an empty array.
  314. *
  315. * @see hook_node_grants()
  316. * @see hook_node_grants_alter()
  317. *
  318. * @param $grants
  319. * The $grants array returned by hook_node_access_records().
  320. * @param $node
  321. * The node for which the grants were acquired.
  322. *
  323. * The preferred use of this hook is in a module that bridges multiple node
  324. * access modules with a configurable behavior, as shown in the example with the
  325. * 'is_preview' field.
  326. *
  327. * @ingroup node_access
  328. */
  329. function hook_node_access_records_alter(&$grants, $node) {
  330. // Our module allows editors to mark specific articles with the 'is_preview'
  331. // field. If the node being saved has a TRUE value for that field, then only
  332. // our grants are retained, and other grants are removed. Doing so ensures
  333. // that our rules are enforced no matter what priority other grants are given.
  334. if ($node->is_preview) {
  335. // Our module grants are set in $grants['example'].
  336. $temp = $grants['example'];
  337. // Now remove all module grants but our own.
  338. $grants = array('example' => $temp);
  339. }
  340. }
  341. /**
  342. * Alter user access rules when trying to view, edit or delete a node.
  343. *
  344. * Node access modules establish rules for user access to content.
  345. * hook_node_grants() defines permissions for a user to view, edit or
  346. * delete nodes by building a $grants array that indicates the permissions
  347. * assigned to the user by each node access module. This hook is called to allow
  348. * modules to modify the $grants array by reference, so the interaction of
  349. * multiple node access modules can be altered or advanced business logic can be
  350. * applied.
  351. *
  352. * @see hook_node_grants()
  353. *
  354. * The resulting grants are then checked against the records stored in the
  355. * {node_access} table to determine if the operation may be completed.
  356. *
  357. * A module may deny all access to a user by setting $grants to an empty array.
  358. *
  359. * @see hook_node_access_records()
  360. * @see hook_node_access_records_alter()
  361. *
  362. * @param $grants
  363. * The $grants array returned by hook_node_grants().
  364. * @param $account
  365. * The user account requesting access to content.
  366. * @param $op
  367. * The operation being performed, 'view', 'update' or 'delete'.
  368. *
  369. * Developers may use this hook to either add additional grants to a user
  370. * or to remove existing grants. These rules are typically based on either the
  371. * permissions assigned to a user role, or specific attributes of a user
  372. * account.
  373. *
  374. * @ingroup node_access
  375. */
  376. function hook_node_grants_alter(&$grants, $account, $op) {
  377. // Our sample module never allows certain roles to edit or delete
  378. // content. Since some other node access modules might allow this
  379. // permission, we expressly remove it by returning an empty $grants
  380. // array for roles specified in our variable setting.
  381. // Get our list of banned roles.
  382. $restricted = variable_get('example_restricted_roles', array());
  383. if ($op != 'view' && !empty($restricted)) {
  384. // Now check the roles for this account against the restrictions.
  385. foreach ($restricted as $role_id) {
  386. if (isset($user->roles[$role_id])) {
  387. $grants = array();
  388. }
  389. }
  390. }
  391. }
  392. /**
  393. * Add mass node operations.
  394. *
  395. * This hook enables modules to inject custom operations into the mass
  396. * operations dropdown found at admin/content, by associating a callback
  397. * function with the operation, which is called when the form is submitted. The
  398. * callback function receives one initial argument, which is an array of the
  399. * checked nodes.
  400. *
  401. * @return
  402. * An array of operations. Each operation is an associative array that may
  403. * contain the following key-value pairs:
  404. * - 'label': Required. The label for the operation, displayed in the dropdown
  405. * menu.
  406. * - 'callback': Required. The function to call for the operation.
  407. * - 'callback arguments': Optional. An array of additional arguments to pass
  408. * to the callback function.
  409. */
  410. function hook_node_operations() {
  411. $operations = array(
  412. 'publish' => array(
  413. 'label' => t('Publish selected content'),
  414. 'callback' => 'node_mass_update',
  415. 'callback arguments' => array('updates' => array('status' => NODE_PUBLISHED)),
  416. ),
  417. 'unpublish' => array(
  418. 'label' => t('Unpublish selected content'),
  419. 'callback' => 'node_mass_update',
  420. 'callback arguments' => array('updates' => array('status' => NODE_NOT_PUBLISHED)),
  421. ),
  422. 'promote' => array(
  423. 'label' => t('Promote selected content to front page'),
  424. 'callback' => 'node_mass_update',
  425. 'callback arguments' => array('updates' => array('status' => NODE_PUBLISHED, 'promote' => NODE_PROMOTED)),
  426. ),
  427. 'demote' => array(
  428. 'label' => t('Demote selected content from front page'),
  429. 'callback' => 'node_mass_update',
  430. 'callback arguments' => array('updates' => array('promote' => NODE_NOT_PROMOTED)),
  431. ),
  432. 'sticky' => array(
  433. 'label' => t('Make selected content sticky'),
  434. 'callback' => 'node_mass_update',
  435. 'callback arguments' => array('updates' => array('status' => NODE_PUBLISHED, 'sticky' => NODE_STICKY)),
  436. ),
  437. 'unsticky' => array(
  438. 'label' => t('Make selected content not sticky'),
  439. 'callback' => 'node_mass_update',
  440. 'callback arguments' => array('updates' => array('sticky' => NODE_NOT_STICKY)),
  441. ),
  442. 'delete' => array(
  443. 'label' => t('Delete selected content'),
  444. 'callback' => NULL,
  445. ),
  446. );
  447. return $operations;
  448. }
  449. /**
  450. * Respond to node deletion.
  451. *
  452. * This hook is invoked from node_delete_multiple() after the type-specific
  453. * hook_delete() has been invoked, but before hook_entity_delete and
  454. * field_attach_delete() are called, and before the node is removed from the
  455. * node table in the database.
  456. *
  457. * @param $node
  458. * The node that is being deleted.
  459. *
  460. * @ingroup node_api_hooks
  461. */
  462. function hook_node_delete($node) {
  463. db_delete('mytable')
  464. ->condition('nid', $node->nid)
  465. ->execute();
  466. }
  467. /**
  468. * Respond to deletion of a node revision.
  469. *
  470. * This hook is invoked from node_revision_delete() after the revision has been
  471. * removed from the node_revision table, and before
  472. * field_attach_delete_revision() is called.
  473. *
  474. * @param $node
  475. * The node revision (node object) that is being deleted.
  476. *
  477. * @ingroup node_api_hooks
  478. */
  479. function hook_node_revision_delete($node) {
  480. db_delete('mytable')
  481. ->condition('vid', $node->vid)
  482. ->execute();
  483. }
  484. /**
  485. * Respond to creation of a new node.
  486. *
  487. * This hook is invoked from node_save() after the node is inserted into the
  488. * node table in the database, after the type-specific hook_insert() is invoked,
  489. * and after field_attach_insert() is called.
  490. *
  491. * @param $node
  492. * The node that is being created.
  493. *
  494. * @ingroup node_api_hooks
  495. */
  496. function hook_node_insert($node) {
  497. db_insert('mytable')
  498. ->fields(array(
  499. 'nid' => $node->nid,
  500. 'extra' => $node->extra,
  501. ))
  502. ->execute();
  503. }
  504. /**
  505. * Act on nodes being loaded from the database.
  506. *
  507. * This hook is invoked during node loading, which is handled by entity_load(),
  508. * via classes NodeController and DrupalDefaultEntityController. After the node
  509. * information is read from the database or the entity cache, hook_load() is
  510. * invoked on the node's content type module, then field_attach_node_revision()
  511. * or field_attach_load() is called, then hook_entity_load() is invoked on all
  512. * implementing modules, and finally hook_node_load() is invoked on all
  513. * implementing modules.
  514. *
  515. * This hook should only be used to add information that is not in the node or
  516. * node revisions table, not to replace information that is in these tables
  517. * (which could interfere with the entity cache). For performance reasons,
  518. * information for all available nodes should be loaded in a single query where
  519. * possible.
  520. *
  521. * The $types parameter allows for your module to have an early return (for
  522. * efficiency) if your module only supports certain node types. However, if your
  523. * module defines a content type, you can use hook_load() to respond to loading
  524. * of just that content type.
  525. *
  526. * @param $nodes
  527. * An array of the nodes being loaded, keyed by nid.
  528. * @param $types
  529. * An array containing the types of the nodes.
  530. *
  531. * For a detailed usage example, see nodeapi_example.module.
  532. *
  533. * @ingroup node_api_hooks
  534. */
  535. function hook_node_load($nodes, $types) {
  536. $result = db_query('SELECT nid, foo FROM {mytable} WHERE nid IN(:nids)', array(':nids' => array_keys($nodes)));
  537. foreach ($result as $record) {
  538. $nodes[$record->nid]->foo = $record->foo;
  539. }
  540. }
  541. /**
  542. * Control access to a node.
  543. *
  544. * Modules may implement this hook if they want to have a say in whether or not
  545. * a given user has access to perform a given operation on a node.
  546. *
  547. * The administrative account (user ID #1) always passes any access check,
  548. * so this hook is not called in that case. Users with the "bypass node access"
  549. * permission may always view and edit content through the administrative
  550. * interface.
  551. *
  552. * Note that not all modules will want to influence access on all
  553. * node types. If your module does not want to actively grant or
  554. * block access, return NODE_ACCESS_IGNORE or simply return nothing.
  555. * Blindly returning FALSE will break other node access modules.
  556. *
  557. * @link http://api.drupal.org/api/group/node_access/7 More on the node access system @endlink
  558. * @ingroup node_access
  559. * @param $node
  560. * The node on which the operation is to be performed, or, if it does
  561. * not yet exist, the type of node to be created.
  562. * @param $op
  563. * The operation to be performed. Possible values:
  564. * - "create"
  565. * - "delete"
  566. * - "update"
  567. * - "view"
  568. * @param $account
  569. * A user object representing the user for whom the operation is to be
  570. * performed.
  571. *
  572. * @return
  573. * NODE_ACCESS_ALLOW if the operation is to be allowed;
  574. * NODE_ACCESS_DENY if the operation is to be denied;
  575. * NODE_ACCESS_IGNORE to not affect this operation at all.
  576. */
  577. function hook_node_access($node, $op, $account) {
  578. $type = is_string($node) ? $node : $node->type;
  579. if (in_array($type, node_permissions_get_configured_types())) {
  580. if ($op == 'create' && user_access('create ' . $type . ' content', $account)) {
  581. return NODE_ACCESS_ALLOW;
  582. }
  583. if ($op == 'update') {
  584. if (user_access('edit any ' . $type . ' content', $account) || (user_access('edit own ' . $type . ' content', $account) && ($account->uid == $node->uid))) {
  585. return NODE_ACCESS_ALLOW;
  586. }
  587. }
  588. if ($op == 'delete') {
  589. if (user_access('delete any ' . $type . ' content', $account) || (user_access('delete own ' . $type . ' content', $account) && ($account->uid == $node->uid))) {
  590. return NODE_ACCESS_ALLOW;
  591. }
  592. }
  593. }
  594. // Returning nothing from this function would have the same effect.
  595. return NODE_ACCESS_IGNORE;
  596. }
  597. /**
  598. * Act on a node object about to be shown on the add/edit form.
  599. *
  600. * This hook is invoked from node_object_prepare() after the type-specific
  601. * hook_prepare() is invoked.
  602. *
  603. * @param $node
  604. * The node that is about to be shown on the add/edit form.
  605. *
  606. * @ingroup node_api_hooks
  607. */
  608. function hook_node_prepare($node) {
  609. if (!isset($node->comment)) {
  610. $node->comment = variable_get("comment_$node->type", COMMENT_NODE_OPEN);
  611. }
  612. }
  613. /**
  614. * Act on a node being displayed as a search result.
  615. *
  616. * This hook is invoked from node_search_execute(), after node_load()
  617. * and node_view() have been called.
  618. *
  619. * @param $node
  620. * The node being displayed in a search result.
  621. *
  622. * @return array
  623. * Extra information to be displayed with search result. This information
  624. * should be presented as an associative array. It will be concatenated
  625. * with the post information (last updated, author) in the default search
  626. * result theming.
  627. *
  628. * @see template_preprocess_search_result()
  629. * @see search-result.tpl.php
  630. *
  631. * @ingroup node_api_hooks
  632. */
  633. function hook_node_search_result($node) {
  634. $comments = db_query('SELECT comment_count FROM {node_comment_statistics} WHERE nid = :nid', array('nid' => $node->nid))->fetchField();
  635. return array('comment' => format_plural($comments, '1 comment', '@count comments'));
  636. }
  637. /**
  638. * Act on a node being inserted or updated.
  639. *
  640. * This hook is invoked from node_save() before the node is saved to the
  641. * database.
  642. *
  643. * @param $node
  644. * The node that is being inserted or updated.
  645. *
  646. * @ingroup node_api_hooks
  647. */
  648. function hook_node_presave($node) {
  649. if ($node->nid && $node->moderate) {
  650. // Reset votes when node is updated:
  651. $node->score = 0;
  652. $node->users = '';
  653. $node->votes = 0;
  654. }
  655. }
  656. /**
  657. * Respond to updates to a node.
  658. *
  659. * This hook is invoked from node_save() after the node is updated in the node
  660. * table in the database, after the type-specific hook_update() is invoked, and
  661. * after field_attach_update() is called.
  662. *
  663. * @param $node
  664. * The node that is being updated.
  665. *
  666. * @ingroup node_api_hooks
  667. */
  668. function hook_node_update($node) {
  669. db_update('mytable')
  670. ->fields(array('extra' => $node->extra))
  671. ->condition('nid', $node->nid)
  672. ->execute();
  673. }
  674. /**
  675. * Act on a node being indexed for searching.
  676. *
  677. * This hook is invoked during search indexing, after node_load(), and after
  678. * the result of node_view() is added as $node->rendered to the node object.
  679. *
  680. * @param $node
  681. * The node being indexed.
  682. *
  683. * @return
  684. * Array of additional information to be indexed.
  685. *
  686. * @ingroup node_api_hooks
  687. */
  688. function hook_node_update_index($node) {
  689. $text = '';
  690. $comments = db_query('SELECT subject, comment, format FROM {comment} WHERE nid = :nid AND status = :status', array(':nid' => $node->nid, ':status' => COMMENT_PUBLISHED));
  691. foreach ($comments as $comment) {
  692. $text .= '<h2>' . check_plain($comment->subject) . '</h2>' . check_markup($comment->comment, $comment->format, '', TRUE);
  693. }
  694. return $text;
  695. }
  696. /**
  697. * Perform node validation before a node is created or updated.
  698. *
  699. * This hook is invoked from node_validate(), after a user has has finished
  700. * editing the node and is previewing or submitting it. It is invoked at the
  701. * end of all the standard validation steps, and after the type-specific
  702. * hook_validate() is invoked.
  703. *
  704. * To indicate a validation error, use form_set_error().
  705. *
  706. * Note: Changes made to the $node object within your hook implementation will
  707. * have no effect. The preferred method to change a node's content is to use
  708. * hook_node_presave() instead. If it is really necessary to change
  709. * the node at the validate stage, you can use form_set_value().
  710. *
  711. * @param $node
  712. * The node being validated.
  713. * @param $form
  714. * The form being used to edit the node.
  715. * @param $form_state
  716. * The form state array.
  717. *
  718. * @ingroup node_api_hooks
  719. */
  720. function hook_node_validate($node, $form, &$form_state) {
  721. if (isset($node->end) && isset($node->start)) {
  722. if ($node->start > $node->end) {
  723. form_set_error('time', t('An event may not end before it starts.'));
  724. }
  725. }
  726. }
  727. /**
  728. * Act on a node after validated form values have been copied to it.
  729. *
  730. * This hook is invoked when a node form is submitted with either the "Save" or
  731. * "Preview" button, after form values have been copied to the form state's node
  732. * object, but before the node is saved or previewed. It is a chance for modules
  733. * to adjust the node's properties from what they are simply after a copy from
  734. * $form_state['values']. This hook is intended for adjusting non-field-related
  735. * properties. See hook_field_attach_submit() for customizing field-related
  736. * properties.
  737. *
  738. * @param $node
  739. * The node object being updated in response to a form submission.
  740. * @param $form
  741. * The form being used to edit the node.
  742. * @param $form_state
  743. * The form state array.
  744. *
  745. * @ingroup node_api_hooks
  746. */
  747. function hook_node_submit($node, $form, &$form_state) {
  748. // Decompose the selected menu parent option into 'menu_name' and 'plid', if
  749. // the form used the default parent selection widget.
  750. if (!empty($form_state['values']['menu']['parent'])) {
  751. list($node->menu['menu_name'], $node->menu['plid']) = explode(':', $form_state['values']['menu']['parent']);
  752. }
  753. }
  754. /**
  755. * Act on a node that is being assembled before rendering.
  756. *
  757. * The module may add elements to $node->content prior to rendering. This hook
  758. * will be called after hook_view(). The structure of $node->content is a
  759. * renderable array as expected by drupal_render().
  760. *
  761. * When $view_mode is 'rss', modules can also add extra RSS elements and
  762. * namespaces to $node->rss_elements and $node->rss_namespaces respectively for
  763. * the RSS item generated for this node.
  764. * For details on how this is used, see node_feed().
  765. *
  766. * @see blog_node_view()
  767. * @see forum_node_view()
  768. * @see comment_node_view()
  769. *
  770. * @param $node
  771. * The node that is being assembled for rendering.
  772. * @param $view_mode
  773. * The $view_mode parameter from node_view().
  774. * @param $langcode
  775. * The language code used for rendering.
  776. *
  777. * @see hook_entity_view()
  778. *
  779. * @ingroup node_api_hooks
  780. */
  781. function hook_node_view($node, $view_mode, $langcode) {
  782. $node->content['my_additional_field'] = array(
  783. '#markup' => $additional_field,
  784. '#weight' => 10,
  785. '#theme' => 'mymodule_my_additional_field',
  786. );
  787. }
  788. /**
  789. * Alter the results of node_view().
  790. *
  791. * This hook is called after the content has been assembled in a structured
  792. * array and may be used for doing processing which requires that the complete
  793. * node content structure has been built.
  794. *
  795. * If the module wishes to act on the rendered HTML of the node rather than the
  796. * structured content array, it may use this hook to add a #post_render
  797. * callback. Alternatively, it could also implement hook_preprocess_node(). See
  798. * drupal_render() and theme() documentation respectively for details.
  799. *
  800. * @param $build
  801. * A renderable array representing the node content.
  802. *
  803. * @see node_view()
  804. * @see hook_entity_view_alter()
  805. *
  806. * @ingroup node_api_hooks
  807. */
  808. function hook_node_view_alter(&$build) {
  809. if ($build['#view_mode'] == 'full' && isset($build['an_additional_field'])) {
  810. // Change its weight.
  811. $build['an_additional_field']['#weight'] = -10;
  812. }
  813. // Add a #post_render callback to act on the rendered HTML of the node.
  814. $build['#post_render'][] = 'my_module_node_post_render';
  815. }
  816. /**
  817. * Define module-provided node types.
  818. *
  819. * This hook allows a module to define one or more of its own node types. For
  820. * example, the blog module uses it to define a blog node-type named "Blog
  821. * entry." The name and attributes of each desired node type are specified in
  822. * an array returned by the hook.
  823. *
  824. * Only module-provided node types should be defined through this hook. User-
  825. * provided (or 'custom') node types should be defined only in the 'node_type'
  826. * database table, and should be maintained by using the node_type_save() and
  827. * node_type_delete() functions.
  828. *
  829. * @return
  830. * An array of information defining the module's node types. The array
  831. * contains a sub-array for each node type, with the machine-readable type
  832. * name as the key. Each sub-array has up to 10 attributes. Possible
  833. * attributes:
  834. * - "name": the human-readable name of the node type. Required.
  835. * - "base": the base string used to construct callbacks corresponding to
  836. * this node type.
  837. * (i.e. if base is defined as example_foo, then example_foo_insert will
  838. * be called when inserting a node of that type). This string is usually
  839. * the name of the module, but not always. Required.
  840. * - "description": a brief description of the node type. Required.
  841. * - "help": help information shown to the user when creating a node of
  842. * this type.. Optional (defaults to '').
  843. * - "has_title": boolean indicating whether or not this node type has a title
  844. * field. Optional (defaults to TRUE).
  845. * - "title_label": the label for the title field of this content type.
  846. * Optional (defaults to 'Title').
  847. * - "locked": boolean indicating whether the administrator can change the
  848. * machine name of this type. FALSE = changeable (not locked),
  849. * TRUE = unchangeable (locked). Optional (defaults to TRUE).
  850. *
  851. * The machine-readable name of a node type should contain only letters,
  852. * numbers, and underscores. Underscores will be converted into hyphens for the
  853. * purpose of constructing URLs.
  854. *
  855. * All attributes of a node type that are defined through this hook (except for
  856. * 'locked') can be edited by a site administrator. This includes the
  857. * machine-readable name of a node type, if 'locked' is set to FALSE.
  858. *
  859. * @ingroup node_api_hooks
  860. */
  861. function hook_node_info() {
  862. return array(
  863. 'blog' => array(
  864. 'name' => t('Blog entry'),
  865. 'base' => 'blog',
  866. 'description' => t('Use for multi-user blogs. Every user gets a personal blog.'),
  867. )
  868. );
  869. }
  870. /**
  871. * Provide additional methods of scoring for core search results for nodes.
  872. *
  873. * A node's search score is used to rank it among other nodes matched by the
  874. * search, with the highest-ranked nodes appearing first in the search listing.
  875. *
  876. * For example, a module allowing users to vote on content could expose an
  877. * option to allow search results' rankings to be influenced by the average
  878. * voting score of a node.
  879. *
  880. * All scoring mechanisms are provided as options to site administrators, and
  881. * may be tweaked based on individual sites or disabled altogether if they do
  882. * not make sense. Individual scoring mechanisms, if enabled, are assigned a
  883. * weight from 1 to 10. The weight represents the factor of magnification of
  884. * the ranking mechanism, with higher-weighted ranking mechanisms having more
  885. * influence. In order for the weight system to work, each scoring mechanism
  886. * must return a value between 0 and 1 for every node. That value is then
  887. * multiplied by the administrator-assigned weight for the ranking mechanism,
  888. * and then the weighted scores from all ranking mechanisms are added, which
  889. * brings about the same result as a weighted average.
  890. *
  891. * @return
  892. * An associative array of ranking data. The keys should be strings,
  893. * corresponding to the internal name of the ranking mechanism, such as
  894. * 'recent', or 'comments'. The values should be arrays themselves, with the
  895. * following keys available:
  896. * - "title": the human readable name of the ranking mechanism. Required.
  897. * - "join": part of a query string to join to any additional necessary
  898. * table. This is not necessary if the table required is already joined to
  899. * by the base query, such as for the {node} table. Other tables should use
  900. * the full table name as an alias to avoid naming collisions. Optional.
  901. * - "score": part of a query string to calculate the score for the ranking
  902. * mechanism based on values in the database. This does not need to be
  903. * wrapped in parentheses, as it will be done automatically; it also does
  904. * not need to take the weighted system into account, as it will be done
  905. * automatically. It does, however, need to calculate a decimal between
  906. * 0 and 1; be careful not to cast the entire score to an integer by
  907. * inadvertently introducing a variable argument. Required.
  908. * - "arguments": if any arguments are required for the score, they can be
  909. * specified in an array here.
  910. *
  911. * @ingroup node_api_hooks
  912. */
  913. function hook_ranking() {
  914. // If voting is disabled, we can avoid returning the array, no hard feelings.
  915. if (variable_get('vote_node_enabled', TRUE)) {
  916. return array(
  917. 'vote_average' => array(
  918. 'title' => t('Average vote'),
  919. // Note that we use i.sid, the search index's search item id, rather than
  920. // n.nid.
  921. 'join' => 'LEFT JOIN {vote_node_data} vote_node_data ON vote_node_data.nid = i.sid',
  922. // The highest possible score should be 1, and the lowest possible score,
  923. // always 0, should be 0.
  924. 'score' => 'vote_node_data.average / CAST(%f AS DECIMAL)',
  925. // Pass in the highest possible voting score as a decimal argument.
  926. 'arguments' => array(variable_get('vote_score_max', 5)),
  927. ),
  928. );
  929. }
  930. }
  931. /**
  932. * Respond to node type creation.
  933. *
  934. * This hook is invoked from node_type_save() after the node type is added
  935. * to the database.
  936. *
  937. * @param $info
  938. * The node type object that is being created.
  939. */
  940. function hook_node_type_insert($info) {
  941. }
  942. /**
  943. * Respond to node type updates.
  944. *
  945. * This hook is invoked from node_type_save() after the node type is updated
  946. * in the database.
  947. *
  948. * @param $info
  949. * The node type object that is being updated.
  950. */
  951. function hook_node_type_update($info) {
  952. if (!empty($info->old_type) && $info->old_type != $info->type) {
  953. $setting = variable_get('comment_' . $info->old_type, COMMENT_NODE_OPEN);
  954. variable_del('comment_' . $info->old_type);
  955. variable_set('comment_' . $info->type, $setting);
  956. }
  957. }
  958. /**
  959. * Respond to node type deletion.
  960. *
  961. * This hook is invoked from node_type_delete() after the node type is removed
  962. * from the database.
  963. *
  964. * @param $info
  965. * The node type object that is being deleted.
  966. */
  967. function hook_node_type_delete($info) {
  968. variable_del('comment_' . $info->type);
  969. }
  970. /**
  971. * Respond to node deletion.
  972. *
  973. * This hook is invoked only on the module that defines the node's content type
  974. * (use hook_node_delete() to respond to all node deletions).
  975. *
  976. * This hook is invoked from node_delete_multiple() after the node has been
  977. * removed from the node table in the database, before hook_node_delete() is
  978. * invoked, and before field_attach_delete() is called.
  979. *
  980. * @param $node
  981. * The node that is being deleted.
  982. *
  983. * @ingroup node_api_hooks
  984. */
  985. function hook_delete($node) {
  986. db_delete('mytable')
  987. ->condition('nid', $node->nid)
  988. ->execute();
  989. }
  990. /**
  991. * Act on a node object about to be shown on the add/edit form.
  992. *
  993. * This hook is invoked only on the module that defines the node's content type
  994. * (use hook_node_prepare() to act on all node preparations).
  995. *
  996. * This hook is invoked from node_object_prepare() before the general
  997. * hook_node_prepare() is invoked.
  998. *
  999. * @param $node
  1000. * The node that is about to be shown on the add/edit form.
  1001. *
  1002. * @ingroup node_api_hooks
  1003. */
  1004. function hook_prepare($node) {
  1005. if ($file = file_check_upload($field_name)) {
  1006. $file = file_save_upload($field_name, _image_filename($file->filename, NULL, TRUE));
  1007. if ($file) {
  1008. if (!image_get_info($file->uri)) {
  1009. form_set_error($field_name, t('Uploaded file is not a valid image'));
  1010. return;
  1011. }
  1012. }
  1013. else {
  1014. return;
  1015. }
  1016. $node->images['_original'] = $file->uri;
  1017. _image_build_derivatives($node, TRUE);
  1018. $node->new_file = TRUE;
  1019. }
  1020. }
  1021. /**
  1022. * Display a node editing form.
  1023. *
  1024. * This hook, implemented by node modules, is called to retrieve the form
  1025. * that is displayed to create or edit a node. This form is displayed at path
  1026. * node/add/[node type] or node/[node ID]/edit.
  1027. *
  1028. * The submit and preview buttons, administrative and display controls, and
  1029. * sections added by other modules (such as path settings, menu settings,
  1030. * comment settings, and fields managed by the Field UI module) are
  1031. * displayed automatically by the node module. This hook just needs to
  1032. * return the node title and form editing fields specific to the node type.
  1033. *
  1034. * @param $node
  1035. * The node being added or edited.
  1036. * @param $form_state
  1037. * The form state array.
  1038. *
  1039. * @return
  1040. * An array containing the title and any custom form elements to be displayed
  1041. * in the node editing form.
  1042. *
  1043. * @ingroup node_api_hooks
  1044. */
  1045. function hook_form($node, &$form_state) {
  1046. $type = node_type_get_type($node);
  1047. $form['title'] = array(
  1048. '#type' => 'textfield',
  1049. '#title' => check_plain($type->title_label),
  1050. '#default_value' => !empty($node->title) ? $node->title : '',
  1051. '#required' => TRUE, '#weight' => -5
  1052. );
  1053. $form['field1'] = array(
  1054. '#type' => 'textfield',
  1055. '#title' => t('Custom field'),
  1056. '#default_value' => $node->field1,
  1057. '#maxlength' => 127,
  1058. );
  1059. $form['selectbox'] = array(
  1060. '#type' => 'select',
  1061. '#title' => t('Select box'),
  1062. '#default_value' => $node->selectbox,
  1063. '#options' => array(
  1064. 1 => 'Option A',
  1065. 2 => 'Option B',
  1066. 3 => 'Option C',
  1067. ),
  1068. '#description' => t('Choose an option.'),
  1069. );
  1070. return $form;
  1071. }
  1072. /**
  1073. * Respond to creation of a new node.
  1074. *
  1075. * This hook is invoked only on the module that defines the node's content type
  1076. * (use hook_node_insert() to act on all node insertions).
  1077. *
  1078. * This hook is invoked from node_save() after the node is inserted into the
  1079. * node table in the database, before field_attach_insert() is called, and
  1080. * before hook_node_insert() is invoked.
  1081. *
  1082. * @param $node
  1083. * The node that is being created.
  1084. *
  1085. * @ingroup node_api_hooks
  1086. */
  1087. function hook_insert($node) {
  1088. db_insert('mytable')
  1089. ->fields(array(
  1090. 'nid' => $node->nid,
  1091. 'extra' => $node->extra,
  1092. ))
  1093. ->execute();
  1094. }
  1095. /**
  1096. * Act on nodes being loaded from the database.
  1097. *
  1098. * This hook is invoked only on the module that defines the node's content type
  1099. * (use hook_node_load() to respond to all node loads).
  1100. *
  1101. * This hook is invoked during node loading, which is handled by entity_load(),
  1102. * via classes NodeController and DrupalDefaultEntityController. After the node
  1103. * information is read from the database or the entity cache, hook_load() is
  1104. * invoked on the node's content type module, then field_attach_node_revision()
  1105. * or field_attach_load() is called, then hook_entity_load() is invoked on all
  1106. * implementing modules, and finally hook_node_load() is invoked on all
  1107. * implementing modules.
  1108. *
  1109. * This hook should only be used to add information that is not in the node or
  1110. * node revisions table, not to replace information that is in these tables
  1111. * (which could interfere with the entity cache). For performance reasons,
  1112. * information for all available nodes should be loaded in a single query where
  1113. * possible.
  1114. *
  1115. * @param $nodes
  1116. * An array of the nodes being loaded, keyed by nid.
  1117. *
  1118. * For a detailed usage example, see node_example.module.
  1119. *
  1120. * @ingroup node_api_hooks
  1121. */
  1122. function hook_load($nodes) {
  1123. $result = db_query('SELECT nid, foo FROM {mytable} WHERE nid IN (:nids)', array(':nids' => array_keys($nodes)));
  1124. foreach ($result as $record) {
  1125. $nodes[$record->nid]->foo = $record->foo;
  1126. }
  1127. }
  1128. /**
  1129. * Respond to updates to a node.
  1130. *
  1131. * This hook is invoked only on the module that defines the node's content type
  1132. * (use hook_node_update() to act on all node updates).
  1133. *
  1134. * This hook is invoked from node_save() after the node is updated in the
  1135. * node table in the database, before field_attach_update() is called, and
  1136. * before hook_node_update() is invoked.
  1137. *
  1138. * @param $node
  1139. * The node that is being updated.
  1140. *
  1141. * @ingroup node_api_hooks
  1142. */
  1143. function hook_update($node) {
  1144. db_update('mytable')
  1145. ->fields(array('extra' => $node->extra))
  1146. ->condition('nid', $node->nid)
  1147. ->execute();
  1148. }
  1149. /**
  1150. * Perform node validation before a node is created or updated.
  1151. *
  1152. * This hook is invoked only on the module that defines the node's content type
  1153. * (use hook_node_validate() to act on all node validations).
  1154. *
  1155. * This hook is invoked from node_validate(), after a user has finished
  1156. * editing the node and is previewing or submitting it. It is invoked at the end
  1157. * of all the standard validation steps, and before hook_node_validate() is
  1158. * invoked.
  1159. *
  1160. * To indicate a validation error, use form_set_error().
  1161. *
  1162. * Note: Changes made to the $node object within your hook implementation will
  1163. * have no effect. The preferred method to change a node's content is to use
  1164. * hook_node_presave() instead.
  1165. *
  1166. * @param $node
  1167. * The node being validated.
  1168. * @param $form
  1169. * The form being used to edit the node.
  1170. * @param $form_state
  1171. * The form state array.
  1172. *
  1173. * @ingroup node_api_hooks
  1174. */
  1175. function hook_validate($node, $form, &$form_state) {
  1176. if (isset($node->end) && isset($node->start)) {
  1177. if ($node->start > $node->end) {
  1178. form_set_error('time', t('An event may not end before it starts.'));
  1179. }
  1180. }
  1181. }
  1182. /**
  1183. * Display a node.
  1184. *
  1185. * This is a hook used by node modules. It allows a module to define a
  1186. * custom method of displaying its nodes, usually by displaying extra
  1187. * information particular to that node type.
  1188. *
  1189. * @param $node
  1190. * The node to be displayed, as returned by node_load().
  1191. * @param $view_mode
  1192. * View mode, e.g. 'full', 'teaser', ...
  1193. * @return
  1194. * $node. The passed $node parameter should be modified as necessary and
  1195. * returned so it can be properly presented. Nodes are prepared for display
  1196. * by assembling a structured array, formatted as in the Form API, in
  1197. * $node->content. As with Form API arrays, the #weight property can be
  1198. * used to control the relative positions of added elements. After this
  1199. * hook is invoked, node_view() calls field_attach_view() to add field
  1200. * views to $node->content, and then invokes hook_node_view() and
  1201. * hook_node_view_alter(), so if you want to affect the final
  1202. * view of the node, you might consider implementing one of these hooks
  1203. * instead.
  1204. *
  1205. * For a detailed usage example, see node_example.module.
  1206. *
  1207. * @ingroup node_api_hooks
  1208. */
  1209. function hook_view($node, $view_mode) {
  1210. if ($view_mode == 'full' && node_is_page($node)) {
  1211. $breadcrumb = array();
  1212. $breadcrumb[] = l(t('Home'), NULL);
  1213. $breadcrumb[] = l(t('Example'), 'example');
  1214. $breadcrumb[] = l($node->field1, 'example/' . $node->field1);
  1215. drupal_set_breadcrumb($breadcrumb);
  1216. }
  1217. $node->content['myfield'] = array(
  1218. '#markup' => theme('mymodule_myfield', $node->myfield),
  1219. '#weight' => 1,
  1220. );
  1221. return $node;
  1222. }
  1223. /**
  1224. * @} End of "addtogroup hooks".
  1225. */