summaryrefslogtreecommitdiff
path: root/modules/image
diff options
context:
space:
mode:
Diffstat (limited to 'modules/image')
-rw-r--r--modules/image/image.api.php4
-rw-r--r--modules/image/image.field.inc6
-rw-r--r--modules/image/image.install2
-rw-r--r--modules/image/image.module52
-rw-r--r--modules/image/image.test22
5 files changed, 80 insertions, 6 deletions
diff --git a/modules/image/image.api.php b/modules/image/image.api.php
index 5b635ec74..acb3f9c19 100644
--- a/modules/image/image.api.php
+++ b/modules/image/image.api.php
@@ -55,8 +55,8 @@ function hook_image_effect_info() {
*/
function hook_image_effect_info_alter(&$effects) {
// Override the Image module's crop effect with more options.
- $effect['image_crop']['effect callback'] = 'mymodule_crop_effect';
- $effect['image_crop']['form callback'] = 'mymodule_crop_form';
+ $effects['image_crop']['effect callback'] = 'mymodule_crop_effect';
+ $effects['image_crop']['form callback'] = 'mymodule_crop_form';
}
/**
diff --git a/modules/image/image.field.inc b/modules/image/image.field.inc
index 07cc1e06b..43e118a70 100644
--- a/modules/image/image.field.inc
+++ b/modules/image/image.field.inc
@@ -51,16 +51,18 @@ function image_field_settings_form($field, $instance) {
'#description' => t('Select where the final files should be stored. Private file storage has significantly more overhead than public files, but allows restricted access to files within this field.'),
);
+ // When the user sets the scheme on the UI, even for the first time, it's
+ // updating a field because fields are created on the "Manage fields"
+ // page. So image_field_update_field() can handle this change.
$form['default_image'] = array(
'#title' => t('Default image'),
'#type' => 'managed_file',
'#description' => t('If no image is uploaded, this image will be shown on display.'),
'#default_value' => $field['settings']['default_image'],
- '#upload_location' => 'public://default_images/',
+ '#upload_location' => $settings['uri_scheme'] . '://default_images/',
);
return $form;
-
}
/**
diff --git a/modules/image/image.install b/modules/image/image.install
index fbd20de50..5f096cc2f 100644
--- a/modules/image/image.install
+++ b/modules/image/image.install
@@ -264,7 +264,7 @@ function image_requirements($phase) {
$requirements['image_gd']['severity'] = REQUIREMENT_OK;
}
else {
- $requirements['image_gd']['severity'] = REQUIREMENT_ERROR;
+ $requirements['image_gd']['severity'] = REQUIREMENT_WARNING;
$requirements['image_gd']['description'] = t('The GD Library for PHP is enabled, but was compiled without support for functions used by the rotate and desaturate effects. It was probably compiled using the official GD libraries from http://www.libgd.org instead of the GD library bundled with PHP. You should recompile PHP --with-gd using the bundled GD library. See <a href="http://www.php.net/manual/book.image.php">the PHP manual</a>.');
}
}
diff --git a/modules/image/image.module b/modules/image/image.module
index d2d081c3e..008a36513 100644
--- a/modules/image/image.module
+++ b/modules/image/image.module
@@ -413,6 +413,58 @@ function image_image_style_delete($style) {
}
/**
+ * Implements hook_field_delete_field().
+ */
+function image_field_delete_field($field) {
+ if ($field['type'] != 'image') {
+ return;
+ }
+
+ // The value of a managed_file element can be an array if #extended == TRUE.
+ $fid = (is_array($field['settings']['default_image']) ? $field['settings']['default_image']['fid'] : $field['settings']['default_image']);
+ if ($fid && ($file = file_load($fid))) {
+ file_usage_delete($file, 'image', 'default_image', $field['id']);
+ }
+}
+
+/**
+ * Implements hook_field_update_field().
+ */
+function image_field_update_field($field, $prior_field, $has_data) {
+ if ($field['type'] != 'image') {
+ return;
+ }
+
+ // The value of a managed_file element can be an array if #extended == TRUE.
+ $fid_new = (is_array($field['settings']['default_image']) ? $field['settings']['default_image']['fid'] : $field['settings']['default_image']);
+ $fid_old = (is_array($prior_field['settings']['default_image']) ? $prior_field['settings']['default_image']['fid'] : $prior_field['settings']['default_image']);
+
+ $file_new = $fid_new ? file_load($fid_new) : FALSE;
+
+ if ($fid_new != $fid_old) {
+
+ // Is there a new file?
+ if ($file_new) {
+ $file_new->status = FILE_STATUS_PERMANENT;
+ file_save($file_new);
+ file_usage_add($file_new, 'image', 'default_image', $field['id']);
+ }
+
+ // Is there an old file?
+ if ($fid_old && ($file_old = file_load($fid_old))) {
+ file_usage_delete($file_old, 'image', 'default_image', $field['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
diff --git a/modules/image/image.test b/modules/image/image.test
index 00f79d852..8596d6680 100644
--- a/modules/image/image.test
+++ b/modules/image/image.test
@@ -796,7 +796,7 @@ class ImageFieldDisplayTestCase extends ImageFieldTestCase {
// that would be used on the image field.
$this->assertNoPattern('<div class="(.*?)field-name-' . strtr($field_name, '_', '-') . '(.*?)">', t('No image displayed when no image is attached and no default image specified.'));
- // Add a default image to the imagefield instance.
+ // Add a default image to the public imagefield instance.
$images = $this->drupalGetTestFiles('image');
$edit = array(
'files[field_settings_default_image]' => drupal_realpath($images[0]->uri),
@@ -806,6 +806,7 @@ class ImageFieldDisplayTestCase extends ImageFieldTestCase {
field_info_cache_clear();
$field = field_info_field($field_name);
$image = file_load($field['settings']['default_image']);
+ $this->assertTrue($image->status == FILE_STATUS_PERMANENT, t('The default image status is permanent.'));
$default_output = theme('image', array('path' => $image->uri));
$this->drupalGet('node/' . $node->nid);
$this->assertRaw($default_output, t('Default image displayed when no user supplied image is present.'));
@@ -831,6 +832,25 @@ class ImageFieldDisplayTestCase extends ImageFieldTestCase {
field_info_cache_clear();
$field = field_info_field($field_name);
$this->assertFalse($field['settings']['default_image'], t('Default image removed from field.'));
+ // Create an image field that uses the private:// scheme and test that the
+ // default image works as expected.
+ $private_field_name = strtolower($this->randomName());
+ $this->createImageField($private_field_name, 'article', array('uri_scheme' => 'private'));
+ // Add a default image to the new field.
+ $edit = array(
+ 'files[field_settings_default_image]' => drupal_realpath($images[1]->uri),
+ );
+ $this->drupalPost('admin/structure/types/manage/article/fields/' . $private_field_name, $edit, t('Save settings'));
+ $private_field = field_info_field($private_field_name);
+ $image = file_load($private_field['settings']['default_image']);
+ $this->assertEqual('private', file_uri_scheme($image->uri), t('Default image uses private:// scheme.'));
+ $this->assertTrue($image->status == FILE_STATUS_PERMANENT, t('The default image status is permanent.'));
+ // Create a new node with no image attached and ensure that default private
+ // image is displayed.
+ $node = $this->drupalCreateNode(array('type' => 'article'));
+ $default_output = theme('image', array('path' => $image->uri));
+ $this->drupalGet('node/' . $node->nid);
+ $this->assertRaw($default_output, t('Default private image displayed when no user supplied image is present.'));
}
}