diff --git a/core/modules/content_translation/content_translation.admin.inc b/core/modules/content_translation/content_translation.admin.inc index 63e71fc..c64e1d0 100644 --- a/core/modules/content_translation/content_translation.admin.inc +++ b/core/modules/content_translation/content_translation.admin.inc @@ -463,10 +463,10 @@ function content_translation_translatable_batch($translatable, $field_name, &$co // We need a two-step approach while updating field translations: given // that field-specific update functions might rely on the stored values to - // perform their processing, see for instance file_field_update(), first - // we need to store the new translations and only after we can remove the - // old ones. Otherwise we might have data loss, since the removal of the - // old translations might occur before the new ones are stored. + // perform their processing first we need to store the new translations + // and only after we can remove the old ones. Otherwise we might have data + // loss, since the removal of the old translations might occur before the + // new ones are stored. if ($translatable && isset($entity->{$field_name}[Language::LANGCODE_NOT_SPECIFIED])) { // If the field is being switched to translatable and has data for // Language::LANGCODE_NOT_SPECIFIED then we need to move the data to the right diff --git a/core/modules/file/file.field.inc b/core/modules/file/file.field.inc index 7e693c7..14c9d30 100644 --- a/core/modules/file/file.field.inc +++ b/core/modules/file/file.field.inc @@ -9,257 +9,13 @@ use Drupal\Core\Entity\EntityInterface; /** - * Implements hook_field_info(). - */ -function file_field_info() { - return array( - 'file' => array( - 'label' => t('File'), - 'description' => t('This field stores the ID of a file as an integer value.'), - 'settings' => array( - 'display_field' => 0, - 'display_default' => 0, - 'uri_scheme' => file_default_scheme(), - ), - 'instance_settings' => array( - 'file_extensions' => 'txt', - 'file_directory' => '', - 'max_filesize' => '', - 'description_field' => 0, - ), - 'default_widget' => 'file_generic', - 'default_formatter' => 'file_default', - 'class' => '\Drupal\file\Type\FileItem', - ), - ); -} - -/** - * Implements hook_field_settings_form(). - */ -function file_field_settings_form($field, $instance) { - $defaults = field_info_field_settings($field['type']); - $settings = array_merge($defaults, $field['settings']); - - $form['#attached']['library'][] = array('file', 'drupal.file'); - - $form['display_field'] = array( - '#type' => 'checkbox', - '#title' => t('Enable Display field'), - '#default_value' => $settings['display_field'], - '#description' => t('The display option allows users to choose if a file should be shown when viewing the content.'), - ); - $form['display_default'] = array( - '#type' => 'checkbox', - '#title' => t('Files displayed by default'), - '#default_value' => $settings['display_default'], - '#description' => t('This setting only has an effect if the display option is enabled.'), - '#states' => array( - 'visible' => array( - ':input[name="field[settings][display_field]"]' => array('checked' => TRUE), - ), - ), - ); - - $scheme_options = array(); - foreach (file_get_stream_wrappers(STREAM_WRAPPERS_WRITE_VISIBLE) as $scheme => $stream_wrapper) { - $scheme_options[$scheme] = $stream_wrapper['name']; - } - $form['uri_scheme'] = array( - '#type' => 'radios', - '#title' => t('Upload destination'), - '#options' => $scheme_options, - '#default_value' => $settings['uri_scheme'], - '#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.'), - '#disabled' => $field->hasData(), - ); - - return $form; -} - -/** - * Implements hook_field_instance_settings_form(). - */ -function file_field_instance_settings_form($field, $instance) { - $settings = $instance['settings']; - - $form['file_directory'] = array( - '#type' => 'textfield', - '#title' => t('File directory'), - '#default_value' => $settings['file_directory'], - '#description' => t('Optional subdirectory within the upload destination where files will be stored. Do not include preceding or trailing slashes.'), - '#element_validate' => array('_file_generic_settings_file_directory_validate'), - '#weight' => 3, - ); - - // Make the extension list a little more human-friendly by comma-separation. - $extensions = str_replace(' ', ', ', $settings['file_extensions']); - $form['file_extensions'] = array( - '#type' => 'textfield', - '#title' => t('Allowed file extensions'), - '#default_value' => $extensions, - '#description' => t('Separate extensions with a space or comma and do not include the leading dot.'), - '#element_validate' => array('_file_generic_settings_extensions'), - '#weight' => 1, - // By making this field required, we prevent a potential security issue - // that would allow files of any type to be uploaded. - '#required' => TRUE, - ); - - $form['max_filesize'] = array( - '#type' => 'textfield', - '#title' => t('Maximum upload size'), - '#default_value' => $settings['max_filesize'], - '#description' => t('Enter a value like "512" (bytes), "80 KB" (kilobytes) or "50 MB" (megabytes) in order to restrict the allowed file size. If left empty the file sizes will be limited only by PHP\'s maximum post and file upload sizes (current limit %limit).', array('%limit' => format_size(file_upload_max_size()))), - '#size' => 10, - '#element_validate' => array('_file_generic_settings_max_filesize'), - '#weight' => 5, - ); - - $form['description_field'] = array( - '#type' => 'checkbox', - '#title' => t('Enable Description field'), - '#default_value' => isset($settings['description_field']) ? $settings['description_field'] : '', - '#description' => t('The description field allows users to enter a description about the uploaded file.'), - '#parents' => array('instance', 'settings', 'description_field'), - '#weight' => 11, - ); - - return $form; -} - -/** - * Render API callback: Validates the maximum upload size field. - * - * Ensures that a size has been entered and that it can be parsed by - * parse_size(). + * Implements hook_field_info_alter(). * - * This function is assigned as an #element_validate callback in - * file_field_instance_settings_form(). - */ -function _file_generic_settings_max_filesize($element, &$form_state) { - if (!empty($element['#value']) && !is_numeric(parse_size($element['#value']))) { - form_error($element, t('The "!name" option must contain a valid value. You may either leave the text field empty or enter a string like "512" (bytes), "80 KB" (kilobytes) or "50 MB" (megabytes).', array('!name' => t($element['title'])))); - } -} - -/** - * Render API callback: Validates the allowed file extensions field. - * - * This function is assigned as an #element_validate callback in - * file_field_instance_settings_form(). - * - * This doubles as a convenience clean-up function and a validation routine. - * Commas are allowed by the end-user, but ultimately the value will be stored - * as a space-separated list for compatibility with file_validate_extensions(). - */ -function _file_generic_settings_extensions($element, &$form_state) { - if (!empty($element['#value'])) { - $extensions = preg_replace('/([, ]+\.?)/', ' ', trim(strtolower($element['#value']))); - $extensions = array_filter(explode(' ', $extensions)); - $extensions = implode(' ', array_unique($extensions)); - if (!preg_match('/^([a-z0-9]+([.][a-z0-9])* ?)+$/', $extensions)) { - form_error($element, t('The list of allowed extensions is not valid, be sure to exclude leading dots and to separate extensions with a comma or space.')); - } - else { - form_set_value($element, $extensions, $form_state); - } - } -} - -/** - * Render API callback: Validates the file destination field. - * - * Removes slashes from the beginning and end of the destination value and - * ensures that the file directory path is not included at the beginning of the - * value. - * - * This function is assigned as an #element_validate callback in - * file_field_instance_settings_form(). - */ -function _file_generic_settings_file_directory_validate($element, &$form_state) { - // Strip slashes from the beginning and end of $widget['file_directory']. - $value = trim($element['#value'], '\\/'); - form_set_value($element, $value, $form_state); -} - -/** - * Implements hook_field_insert(). - */ -function file_field_insert(EntityInterface $entity, $field, $instance, $langcode, &$items) { - // Add a new usage of each uploaded file. - foreach ($items as $item) { - file_usage()->add(file_load($item['target_id']), 'file', $entity->entityType(), $entity->id()); - } -} - -/** - * Implements hook_field_update(). - * - * Checks for files that have been removed from the object. - */ -function file_field_update(EntityInterface $entity, $field, $instance, $langcode, &$items) { - // On new revisions, all files are considered to be a new usage and no - // deletion of previous file usages are necessary. - if (!empty($entity->original) && $entity->getRevisionId() != $entity->original->getRevisionId()) { - foreach ($items as $item) { - file_usage()->add(file_load($item['target_id']), 'file', $entity->entityType(), $entity->id()); - } - return; - } - - // Build a display of the current FIDs. - $current_fids = array(); - foreach ($items as $item) { - $current_fids[] = $item['target_id']; - } - - // Compare the original field values with the ones that are being saved. - $original = $entity->original->getBCEntity(); - $original_fids = array(); - if (!empty($original->{$field['field_name']}[$langcode])) { - foreach ($original->{$field['field_name']}[$langcode] as $original_item) { - $original_fids[] = $original_item['target_id']; - if (isset($original_item['target_id']) && !in_array($original_item['target_id'], $current_fids)) { - // Decrement the file usage count by 1. - file_usage()->delete(file_load($original_item['target_id']), 'file', $entity->entityType(), $entity->id()); - } - } - } - - // Add new usage entries for newly added files. - foreach ($items as $item) { - if (!in_array($item['target_id'], $original_fids)) { - file_usage()->add(file_load($item['target_id']), 'file', $entity->entityType(), $entity->id()); - } - } -} - -/** - * Implements hook_field_delete(). - */ -function file_field_delete(EntityInterface $entity, $field, $instance, $langcode, &$items) { - // Delete all file usages within this entity. - foreach ($items as $delta => $item) { - file_usage()->delete(file_load($item['target_id']), 'file', $entity->entityType(), $entity->id(), 0); - } -} - -/** - * Implements hook_field_delete_revision(). - */ -function file_field_delete_revision(EntityInterface $entity, $field, $instance, $langcode, &$items) { - foreach ($items as $delta => $item) { - // Decrement the file usage count by 1. - file_usage()->delete(file_load($item['target_id']), 'file', $entity->entityType(), $entity->id()); - } -} - -/** - * Implements hook_field_is_empty(). + * Cannot annotate in FieldItem plugin the settings.uri_scheme meta data key + * with a dynamic value. We need to alter the value here. */ -function file_field_is_empty($item, $field_type) { - return empty($item['target_id']); +function file_field_info_alter(&$info) { + $info['file']['settings']['uri_scheme'] = file_default_scheme(); } /** diff --git a/core/modules/file/file.install b/core/modules/file/file.install index 1f31e43..e57615c 100644 --- a/core/modules/file/file.install +++ b/core/modules/file/file.install @@ -151,44 +151,6 @@ function file_schema() { } /** - * Implements hook_field_schema(). - */ -function file_field_schema($field) { - return array( - 'columns' => array( - 'target_id' => array( - 'description' => 'The ID of the target entity.', - 'type' => 'int', - 'not null' => TRUE, - 'unsigned' => TRUE, - ), - 'display' => array( - 'description' => 'Flag to control whether this file should be displayed when viewing content.', - 'type' => 'int', - 'size' => 'tiny', - 'unsigned' => TRUE, - 'not null' => TRUE, - 'default' => 1, - ), - 'description' => array( - 'description' => 'A description of the file.', - 'type' => 'text', - 'not null' => FALSE, - ), - ), - 'indexes' => array( - 'target_id' => array('target_id'), - ), - 'foreign keys' => array( - 'target_id' => array( - 'table' => 'file_managed', - 'columns' => array('target_id' => 'fid'), - ), - ), - ); -} - -/** * Implements hook_requirements(). * * Display information about getting upload progress bars working. diff --git a/core/modules/file/lib/Drupal/file/FileField.php b/core/modules/file/lib/Drupal/file/FileField.php new file mode 100644 index 0000000..b5aaeb8 --- /dev/null +++ b/core/modules/file/lib/Drupal/file/FileField.php @@ -0,0 +1,72 @@ +updateFileUsage(); + } + + protected function updateFileUsage() { + $entity = $this->getRoot(); + + // On new revisions, all files are considered to be a new usage and no + // deletion of previous file usages are necessary. + if (!empty($entity->original) && $entity->getRevisionId() != $entity->original->getRevisionId()) { + foreach ($this->list as $item) { + $target_id = $item->get('target_id')->getValue(); + file_usage()->add(file_load($target_id), 'file', $entity->entityType(), $entity->id()); + } + return; + } + + // Get the field id. + $field_id = $this->getInstance()->getField()->id(); + + // Build a list of the current target IDs. + $current_fids = array(); + foreach ($this->list as $item) { + $target_id = $item->get('target_id')->getValue(); + $current_fids[] = $target_id; + } + + // Compare the original field values with the ones that are being saved. + $original = $entity->original->getBCEntity(); + $langcode = $original->language()->id; + + $original_fids = array(); + if (!empty($original->{$field_id}[$langcode])) { + foreach ($original->{$field_id}[$langcode] as $original_item) { + $original_fids[] = $original_item['target_id']; + if (isset($original_item['target_id']) && !in_array($original_item['target_id'], $current_fids)) { + // Decrement the file usage count by 1. + file_usage()->delete(file_load($original_item['target_id']), 'file', $entity->entityType(), $entity->id()); + } + } + } + + // Add new usage entries for newly added files. + foreach ($this->list as $item) { + $target_id = $item->get('target_id')->getValue(); + if (!in_array($target_id, $original_fids)) { + file_usage()->add(file_load($target_id), 'file', $entity->entityType(), $entity->id()); + } + } + } + +} diff --git a/core/modules/file/lib/Drupal/file/Plugin/field/field_type/FileItem.php b/core/modules/file/lib/Drupal/file/Plugin/field/field_type/FileItem.php new file mode 100644 index 0000000..06c8645 --- /dev/null +++ b/core/modules/file/lib/Drupal/file/Plugin/field/field_type/FileItem.php @@ -0,0 +1,305 @@ + array( + 'target_id' => array( + 'description' => 'The ID of the file entity.', + 'type' => 'int', + 'not null' => TRUE, + 'unsigned' => TRUE, + ), + 'display' => array( + 'description' => 'Flag to control whether this file should be displayed when viewing content.', + 'type' => 'int', + 'size' => 'tiny', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'default' => 1, + ), + 'description' => array( + 'description' => 'A description of the file.', + 'type' => 'text', + 'not null' => FALSE, + ), + ), + 'indexes' => array( + 'target_id' => array('target_id'), + ), + 'foreign keys' => array( + 'target_id' => array( + 'table' => 'file_managed', + 'columns' => array('target_id' => 'fid'), + ), + ), + ); + } + + /** + * {@inheritdoc} + */ + public function getPropertyDefinitions() { + $this->definition['settings']['target_type'] = 'file'; + // Definitions vary by entity type and bundle, so key them accordingly. + $key = $this->definition['settings']['target_type'] . ':'; + $key .= isset($this->definition['settings']['target_bundle']) ? $this->definition['settings']['target_bundle'] : ''; + + if (!isset(static::$propertyDefinitions[$key])) { + $parent_definitions = parent::getPropertyDefinitions(); + unset($parent_definitions['revision_id'], $parent_definitions['label'], $parent_definitions['access']); + + static::$propertyDefinitions[$key] = $parent_definitions; + + static::$propertyDefinitions[$key]['display'] = array( + 'type' => 'boolean', + 'label' => t('Flag to control whether this file should be displayed when viewing content.'), + ); + static::$propertyDefinitions[$key]['description'] = array( + 'type' => 'string', + 'label' => t('A description of the file.'), + ); + } + return static::$propertyDefinitions[$key]; + } + + /** + * {@inheritdoc} + */ + public function settingsForm(array $form, array &$form_state) { + $element = array(); + + $element['#attached']['library'][] = array('file', 'drupal.file'); + + $element['display_field'] = array( + '#type' => 'checkbox', + '#title' => t('Enable Display field'), + '#default_value' => $this->getFieldDefinition()->getFieldSetting('display_field'), + '#description' => t('The display option allows users to choose if a file should be shown when viewing the content.'), + ); + $element['display_default'] = array( + '#type' => 'checkbox', + '#title' => t('Files displayed by default'), + '#default_value' => $this->getFieldDefinition()->getFieldSetting('display_default'), + '#description' => t('This setting only has an effect if the display option is enabled.'), + '#states' => array( + 'visible' => array( + ':input[name="field[settings][display_field]"]' => array('checked' => TRUE), + ), + ), + ); + + $scheme_options = array(); + foreach (file_get_stream_wrappers(STREAM_WRAPPERS_WRITE_VISIBLE) as $scheme => $stream_wrapper) { + $scheme_options[$scheme] = $stream_wrapper['name']; + } + $element['uri_scheme'] = array( + '#type' => 'radios', + '#title' => t('Upload destination'), + '#options' => $scheme_options, + '#default_value' => $this->getFieldDefinition()->getFieldSetting('uri_scheme'), + '#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.'), + '#disabled' => $this->getInstance()->getField()->hasData(), + ); + + return $element; + } + + /** + * {@inheritdoc} + */ + public function instanceSettingsForm(array $form, array &$form_state) { + $element = array(); + $settings = $this->getFieldDefinition()->getFieldSettings(); + + $element['file_directory'] = array( + '#type' => 'textfield', + '#title' => t('File directory'), + '#default_value' => $settings['file_directory'], + '#description' => t('Optional subdirectory within the upload destination where files will be stored. Do not include preceding or trailing slashes.'), + '#element_validate' => array(array($this, 'validateDirectory')), + '#weight' => 3, + ); + + // Make the extension list a little more human-friendly by comma-separation. + $extensions = str_replace(' ', ', ', $settings['file_extensions']); + $element['file_extensions'] = array( + '#type' => 'textfield', + '#title' => t('Allowed file extensions'), + '#default_value' => $extensions, + '#description' => t('Separate extensions with a space or comma and do not include the leading dot.'), + '#element_validate' => array(array($this, 'validateExtensions')), + '#weight' => 1, + // By making this field required, we prevent a potential security issue + // that would allow files of any type to be uploaded. + '#required' => TRUE, + ); + + $element['max_filesize'] = array( + '#type' => 'textfield', + '#title' => t('Maximum upload size'), + '#default_value' => $settings['max_filesize'], + '#description' => t('Enter a value like "512" (bytes), "80 KB" (kilobytes) or "50 MB" (megabytes) in order to restrict the allowed file size. If left empty the file sizes will be limited only by PHP\'s maximum post and file upload sizes (current limit %limit).', array('%limit' => format_size(file_upload_max_size()))), + '#size' => 10, + '#element_validate' => array(array($this, 'validateMaxFilesize')), + '#weight' => 5, + ); + + $element['description_field'] = array( + '#type' => 'checkbox', + '#title' => t('Enable Description field'), + '#default_value' => isset($settings['description_field']) ? $settings['description_field'] : '', + '#description' => t('The description field allows users to enter a description about the uploaded file.'), + '#parents' => array('instance', 'settings', 'description_field'), + '#weight' => 11, + ); + + return $element; + } + + /** + * {@inheritdoc} + */ + public function insert() { + $entity = $this->getRoot(); + $target_id = $this->get('target_id')->getValue(); + + // Add a new usage for this new uploaded file. + file_usage()->add(file_load($target_id), 'file', $entity->entityType(), $entity->id()); + } + + /** + * {@inheritdoc} + */ + public function delete() { + $entity = $this->getRoot(); + $target_id = $this->get('target_id')->getValue(); + + // Delete all file usages within this entity. + file_usage()->delete(file_load($target_id), 'file', $entity->entityType(), $entity->id(), 0); + } + + /** + * {@inheritdoc} + */ + public function deleteRevision() { + $entity = $this->getRoot(); + $target_id = $this->get('target_id')->getValue(); + + // Decrement the file usage count by 1. + file_usage()->delete(file_load($target_id), 'file', $entity->entityType(), $entity->id()); + } + + /** + * {@inheritdoc} + */ + public function isEmpty() { + $target_id = $this->get('target_id')->getValue(); + return empty($target_id); + } + + /** + * Render API callback: Validates the file destination field. + * + * Removes slashes from the beginning and end of the destination value and + * ensures that the file directory path is not included at the beginning of the + * value. + * + * This function is assigned as an #element_validate callback in + * instanceSettingsForm(). + */ + public function validateDirectory($element, &$form_state) { + // Strip slashes from the beginning and end of $element['file_directory']. + $value = trim($element['#value'], '\\/'); + form_set_value($element, $value, $form_state); + } + + /** + * Render API callback: Validates the allowed file extensions field. + * + * This function is assigned as an #element_validate callback in + * instanceSettingsForm(). + * + * This doubles as a convenience clean-up function and a validation routine. + * Commas are allowed by the end-user, but ultimately the value will be stored + * as a space-separated list for compatibility with file_validate_extensions(). + */ + public function validateExtensions($element, &$form_state) { + if (!empty($element['#value'])) { + $extensions = preg_replace('/([, ]+\.?)/', ' ', trim(strtolower($element['#value']))); + $extensions = array_filter(explode(' ', $extensions)); + $extensions = implode(' ', array_unique($extensions)); + if (!preg_match('/^([a-z0-9]+([.][a-z0-9])* ?)+$/', $extensions)) { + form_error($element, t('The list of allowed extensions is not valid, be sure to exclude leading dots and to separate extensions with a comma or space.')); + } + else { + form_set_value($element, $extensions, $form_state); + } + } + } + + /** + * Render API callback: Validates the maximum upload size field. + * + * Ensures that a size has been entered and that it can be parsed by + * parse_size(). + * + * This function is assigned as an #element_validate callback in + * finstanceSettingsForm(). + */ + public function validateMaxFilesize($element, &$form_state) { + if (!empty($element['#value']) && !is_numeric(parse_size($element['#value']))) { + form_error($element, t('The "!name" option must contain a valid value. You may either leave the text field empty or enter a string like "512" (bytes), "80 KB" (kilobytes) or "50 MB" (megabytes).', array('!name' => t($element['title'])))); + } + } + +} diff --git a/core/modules/file/lib/Drupal/file/Type/FileItem.php b/core/modules/file/lib/Drupal/file/Type/FileItem.php deleted file mode 100644 index c8f1a9c..0000000 --- a/core/modules/file/lib/Drupal/file/Type/FileItem.php +++ /dev/null @@ -1,50 +0,0 @@ -definition['settings']['target_type'] = 'file'; - // Definitions vary by entity type and bundle, so key them accordingly. - $key = $this->definition['settings']['target_type'] . ':'; - $key .= isset($this->definition['settings']['target_bundle']) ? $this->definition['settings']['target_bundle'] : ''; - - if (!isset(static::$propertyDefinitions[$key])) { - static::$propertyDefinitions[$key] = parent::getPropertyDefinitions(); - - static::$propertyDefinitions[$key]['display'] = array( - 'type' => 'boolean', - 'label' => t('Flag to control whether this file should be displayed when viewing content.'), - ); - static::$propertyDefinitions[$key]['description'] = array( - 'type' => 'string', - 'label' => t('A description of the file.'), - ); - } - return static::$propertyDefinitions[$key]; - } - -} diff --git a/core/modules/image/image.field.inc b/core/modules/image/image.field.inc index 1f0e87b..483a94e 100644 --- a/core/modules/image/image.field.inc +++ b/core/modules/image/image.field.inc @@ -9,270 +9,10 @@ use Drupal\Core\Entity\EntityInterface; /** - * Implements hook_field_info(). + * Implements hook_field_info_alter(). */ -function image_field_info() { - return array( - 'image' => array( - 'label' => t('Image'), - 'description' => t('This field stores the ID of an image file as an integer value.'), - 'settings' => array( - 'uri_scheme' => file_default_scheme(), - 'default_image' => 0, - 'column_groups' => array( - 'file' => array( - 'label' => t('File'), - 'columns' => array('target_id', 'width', 'height'), - ), - 'alt' => array( - 'label' => t('Alt'), - 'translatable' => TRUE, - ), - 'title' => array( - 'label' => t('Title'), - 'translatable' => TRUE, - ), - ), - ), - 'instance_settings' => array( - 'file_extensions' => 'png gif jpg jpeg', - 'file_directory' => '', - 'max_filesize' => '', - 'alt_field' => 0, - 'alt_field_required' => 0, - 'title_field' => 0, - 'title_field_required' => 0, - 'max_resolution' => '', - 'min_resolution' => '', - 'default_image' => 0, - ), - 'default_widget' => 'image_image', - 'default_formatter' => 'image', - 'class' => '\Drupal\image\Type\ImageItem', - ), - ); -} - -/** - * Implements hook_field_settings_form(). - */ -function image_field_settings_form($field, $instance) { - $defaults = field_info_field_settings($field['type']); - $settings = array_merge($defaults, $field['settings']); - - $scheme_options = array(); - foreach (file_get_stream_wrappers(STREAM_WRAPPERS_WRITE_VISIBLE) as $scheme => $stream_wrapper) { - $scheme_options[$scheme] = $stream_wrapper['name']; - } - $form['uri_scheme'] = array( - '#type' => 'radios', - '#title' => t('Upload destination'), - '#options' => $scheme_options, - '#default_value' => $settings['uri_scheme'], - '#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' => empty($field['settings']['default_image']) ? array() : array($field['settings']['default_image']), - '#upload_location' => $settings['uri_scheme'] . '://default_images/', - ); - - return $form; -} - -/** - * Implements hook_field_instance_settings_form(). - */ -function image_field_instance_settings_form($field, $instance) { - $settings = $instance['settings']; - - // Use the file field instance settings form as a basis. - $form = file_field_instance_settings_form($field, $instance); - - // Add maximum and minimum resolution settings. - $max_resolution = explode('x', $settings['max_resolution']) + array('', ''); - $form['max_resolution'] = array( - '#type' => 'item', - '#title' => t('Maximum image resolution'), - '#element_validate' => array('_image_field_resolution_validate'), - '#weight' => 4.1, - '#field_prefix' => '