Community Documentation

hook_prepare

5 node.php hook_prepare(&$node)
6 node.php hook_prepare(&$node)
7 node.api.php hook_prepare($node)
8 node.api.php hook_prepare($node)

This is a hook used by node modules. It is called after load but before the node is shown on the add/edit form.

Parameters

&$node: The node being saved.

Return value

None.

For a usage example, see image.module.

Related topics

▾ 4 functions implement hook_prepare()

forum_prepare in modules/forum/forum.module
Implementation of hook_prepare; assign forum taxonomy when adding a topic from within a forum.
node_object_prepare in modules/node/node.module
node_prepare in modules/node/node.module
Apply filters and build the node's standard elements.
_upload_prepare in modules/upload/upload.module
Save new uploads and attach them to the node object. append file_previews to the node object as well.

File

developer/hooks/node.php, line 209
These hooks are defined by node modules, modules that define a new kind of node.

Code

<?php
function hook_prepare(&$node) {
  if ($file = file_check_upload($field_name)) {
    $file = file_save_upload($field_name, _image_filename($file->filename, NULL, TRUE));
    if ($file) {
      if (!image_get_info($file->filepath)) {
        form_set_error($field_name, t('Uploaded file is not a valid image'));
        return;
      }
    }
    else {
      return;
    }
    $node->images['_original'] = $file->filepath;
    _image_build_derivatives($node, true);
    $node->new_file = TRUE;
  }
}
?>
Login or register to post comments