summaryrefslogtreecommitdiff
path: root/modules/image/image.module
diff options
context:
space:
mode:
authorwebchick <webchick@24967.no-reply.drupal.org>2012-04-30 21:25:39 -0700
committerwebchick <webchick@24967.no-reply.drupal.org>2012-04-30 21:25:39 -0700
commitd0b5d31cbca7b5ce521ee180b6ca31e301b63b4e (patch)
treeb28610c70815d08a95e38a5534a858457ed69117 /modules/image/image.module
parent84c4f7622e8cd2c90374e3907069aa256114558f (diff)
downloadbrdo-d0b5d31cbca7b5ce521ee180b6ca31e301b63b4e.tar.gz
brdo-d0b5d31cbca7b5ce521ee180b6ca31e301b63b4e.tar.bz2
Issue #751168 by elliotttf, caktux, andyceo, setvik, xjm, sun, tim.plunkett: Fixed Regression: Missing 'Default image' per field instance.
Diffstat (limited to 'modules/image/image.module')
-rw-r--r--modules/image/image.module67
1 files changed, 67 insertions, 0 deletions
diff --git a/modules/image/image.module b/modules/image/image.module
index 933dbc50a..3bf4b6861 100644
--- a/modules/image/image.module
+++ b/modules/image/image.module
@@ -467,6 +467,73 @@ function image_field_update_field($field, $prior_field, $has_data) {
}
/**
+ * Implements hook_field_delete_instance().
+ */
+function image_field_delete_instance($instance) {
+ // Only act on image fields.
+ $field = field_read_field($instance['field_name']);
+ if ($field['type'] != 'image') {
+ return;
+ }
+
+ // The value of a managed_file element can be an array if the #extended
+ // property is set to TRUE.
+ $fid = $instance['settings']['default_image'];
+ if (is_array($fid)) {
+ $fid = $fid['fid'];
+ }
+
+ // Remove the default image when the instance is deleted.
+ if ($fid && ($file = file_load($fid))) {
+ file_usage_delete($file, 'image', 'default_image', $instance['id']);
+ }
+}
+
+/**
+ * Implements hook_field_update_instance().
+ */
+function image_field_update_instance($instance, $prior_instance) {
+ // Only act on image fields.
+ $field = field_read_field($instance['field_name']);
+ if ($field['type'] != 'image') {
+ return;
+ }
+
+ // The value of a managed_file element can be an array if the #extended
+ // property is set to TRUE.
+ $fid_new = $instance['settings']['default_image'];
+ if (is_array($fid_new)) {
+ $fid_new = $fid_new['fid'];
+ }
+ $fid_old = $prior_instance['settings']['default_image'];
+ if (is_array($fid_old)) {
+ $fid_old = $fid_old['fid'];
+ }
+
+ // If the old and new files do not match, update the default accordingly.
+ $file_new = $fid_new ? file_load($fid_new) : FALSE;
+ if ($fid_new != $fid_old) {
+ // Save the new file, if present.
+ if ($file_new) {
+ $file_new->status = FILE_STATUS_PERMANENT;
+ file_save($file_new);
+ file_usage_add($file_new, 'image', 'default_image', $instance['id']);
+ }
+ // Delete the old file, if present.
+ if ($fid_old && ($file_old = file_load($fid_old))) {
+ file_usage_delete($file_old, 'image', 'default_image', $instance['id']);
+ }
+ }
+
+ // If the upload destination changed, then move the file.
+ if ($file_new && (file_uri_scheme($file_new->uri) != $field['settings']['uri_scheme'])) {
+ $directory = $field['settings']['uri_scheme'] . '://default_images/';
+ file_prepare_directory($directory, FILE_CREATE_DIRECTORY);
+ file_move($file_new, $directory . $file_new->filename);
+ }
+}
+
+/**
* Clear cached versions of a specific file in all styles.
*
* @param $path