Community Documentation

CCK hook_field

Last updated May 18, 2011. Created by Chris Johnson on December 5, 2008.
Edited by Scyther, jaxxed, jec006, lsburton. Log in to edit this page.

Hook_field() defines how the field will actually store and display its contents.

The 'validate' operation provides an opportunity for the field to validate the field data when the node is validated. The $field parameter contains the field settings, which can be used to help in the validation process.

The content module essentially routes hook_nodeapi calls in hook_field calls for every field that is a part of a node type. The module calls both a 'default' version of the hook to perform some precursor cck operations on all of the fields, and the module calls the hook_field call for each field, using the module for which the field is configured. In some operations (validate) the default is executed first, others the order is reversed.
Content passes variables from the hook_nodeapi call to the hook_field, and in some cases returns the hook_field to drupal (but not often.)
If you want more information about the parameters and return values, investigate the hook_nodeapi definition. The content module routes nodeapi calls through methods content_{$op}, which execute _content_field_invoke_default and _content_field_invoke. _content_field_invoke executes the hook_field

<?php
function hook_field($op, &$node, $field, &$items, $teaser, $page)
?>

Possible values of $op:

  • delete
  • delete revision
  • insert
  • load
  • prepare translation
  • presave
  • sanitize
  • update
  • validate

For $op equal to load the expected return value is an associative array of keys=>values to be added to the node object.

The difference between presave and insert/update is that hook_content_is_empty is called after presave and before insert/update.

Page status

About this page

Drupal version
Drupal 6.x

Structure Guide

Drupal’s online documentation is © 2000-2012 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.