hook_prepare

developer/hooks/node.php, line 189

Versions
4.7 – 6
hook_prepare(&$node)
7
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.

For a usage example, see image.module.

Parameters

&$node The node being saved.

Return value

None.

Related topics

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;
  }
}
?>
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.