Act on a node object about to be shown on the add/edit form.
This hook is invoked only on the module that defines the node's content type (use hook_node_prepare() to act on all node preparations).
This hook is invoked from NodeFormController::prepareEntity() before the general hook_node_prepare() is invoked.
Drupal\node\Node $node: The node that is about to be shown on the add/edit form.
Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.
function hook_prepare(Drupal\node\Node $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->uri)) {
form_set_error($field_name, t('Uploaded file is not a valid image'));
return;
}
}
else {
return;
}
$node->images['_original'] = $file->uri;
_image_build_derivatives($node, TRUE);
$node->new_file = TRUE;
}
}