From a155afaa8dfb311845b9d485eb2818cc60830979 Mon Sep 17 00:00:00 2001 From: Claudiu Cristea Date: Tue, 20 Aug 2013 17:05:33 +0300 Subject: [PATCH] Issue #2015697 by claudiu.cristea, Berdir | swentel: Convert field type to typed data plugin for file and image modules. --- .../content_translation.admin.inc | 8 +- .../field/Plugin/Type/FieldType/ConfigField.php | 9 + core/modules/file/file.field.inc | 308 +----------------- core/modules/file/file.install | 39 --- core/modules/file/lib/Drupal/file/FileField.php | 72 ++++ .../file/Plugin/field/field_type/FileItem.php | 362 +++++++++++++++++++++ .../Drupal/file/Plugin/field/widget/FileWidget.php | 6 +- .../modules/file/lib/Drupal/file/Type/FileItem.php | 50 --- core/modules/image/image.field.inc | 266 +-------------- core/modules/image/image.install | 47 --- .../image/Plugin/field/field_type/ImageItem.php | 327 +++++++++++++++++++ .../image/lib/Drupal/image/Type/ImageItem.php | 58 ---- 12 files changed, 784 insertions(+), 768 deletions(-) create mode 100644 core/modules/file/lib/Drupal/file/FileField.php create mode 100644 core/modules/file/lib/Drupal/file/Plugin/field/field_type/FileItem.php delete mode 100644 core/modules/file/lib/Drupal/file/Type/FileItem.php create mode 100644 core/modules/image/lib/Drupal/image/Plugin/field/field_type/ImageItem.php delete mode 100644 core/modules/image/lib/Drupal/image/Type/ImageItem.php diff --git a/core/modules/content_translation/content_translation.admin.inc b/core/modules/content_translation/content_translation.admin.inc index 97cbfa9..f0a1caa 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/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigField.php b/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigField.php index b61b301..8f35f34 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigField.php +++ b/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigField.php @@ -72,4 +72,13 @@ public function getConstraints() { return $constraints; } + /** + * Avoid to serialize the instance; unnecessary and breaks in PHP 5.4. + */ + public function __sleep() { + $vars = get_class_vars(get_class($this)); + unset($vars['instance']); + return array_keys($vars); + } + } diff --git a/core/modules/file/file.field.inc b/core/modules/file/file.field.inc index 3e3806e..1eb4662 100644 --- a/core/modules/file/file.field.inc +++ b/core/modules/file/file.field.inc @@ -6,313 +6,15 @@ */ use Drupal\Component\Utility\NestedArray; -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 = \Drupal::service('plugin.manager.entity.field.field_type')->getDefaultSettings($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(). - * - * 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(). + * Implements hook_field_info_alter(). * - * 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(). + * 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_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(). - */ -function file_field_is_empty($item, $field_type) { - return empty($item['target_id']); -} - -/** - * Retrieves the upload validators for a file field. - * - * @param array $field_settings - * The field settings. - * - * @return - * An array suitable for passing to file_save_upload() or the file field - * element's '#upload_validators' property. - */ -function file_field_widget_upload_validators(array $field_settings) { - // Cap the upload size according to the PHP limit. - $max_filesize = parse_size(file_upload_max_size()); - if (!empty($field_settings['max_filesize']) && parse_size($field_settings['max_filesize']) < $max_filesize) { - $max_filesize = parse_size($field_settings['max_filesize']); - } - - $validators = array(); - - // There is always a file size limit due to the PHP server limit. - $validators['file_validate_size'] = array($max_filesize); - - // Add the extension check if necessary. - if (!empty($field_settings['file_extensions'])) { - $validators['file_validate_extensions'] = array($field_settings['file_extensions']); - } - - return $validators; -} - -/** - * Determines the URI for a file field. - * - * @param array $field_settings - * The field settings. - * @param $data - * An array of token objects to pass to - * \Drupal\Core\Utility\Token::replace(). - * - * @return - * A file directory URI with tokens replaced. - * - * @see \Drupal\Core\Utility\Token::replace() - */ -function file_field_widget_uri(array $field_settings, $data = array()) { - $destination = trim($field_settings['file_directory'], '/'); - - // Replace tokens. - $destination = Drupal::token()->replace($destination, $data); - - return $field_settings['uri_scheme'] . '://' . $destination; +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 39d671c..754e990 100644 --- a/core/modules/file/file.install +++ b/core/modules/file/file.install @@ -152,44 +152,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. @@ -355,4 +317,3 @@ function file_update_8004() { ); db_change_field('file_managed', 'filesize', 'filesize', $spec); } - 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..8eb6048 --- /dev/null +++ b/core/modules/file/lib/Drupal/file/Plugin/field/field_type/FileItem.php @@ -0,0 +1,362 @@ +instance) && $parent = $this->getParent()) { + $this->instance = $parent->getInstance(); + } + return $this->instance; + } + + /** + * {@inheritdoc} + */ + public static function schema(FieldInterface $field) { + return array( + 'columns' => 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])) { + 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]; + } + + /** + * {@inheritdoc} + */ + public function settingsForm(array $form, array &$form_state, $has_data) { + $element = array(); + + $element['#attached']['library'][] = array('file', 'drupal.file'); + + $element['display_field'] = array( + '#type' => 'checkbox', + '#title' => t('Enable Display field'), + '#default_value' => $this->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->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->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' => $has_data, + ); + + return $element; + } + + /** + * {@inheritdoc} + */ + public function instanceSettingsForm(array $form, array &$form_state) { + $element = array(); + $settings = $this->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'])))); + } + } + + /** + * Determines the URI for a file field instance. + * + * @param $data + * An array of token objects to pass to token_replace(). + * + * @return + * A file directory URI with tokens replaced. + * + * @see token_replace() + */ + public function getUri($data = array()) { + $settings = $this->getFieldSettings(); + $destination = trim($settings['file_directory'], '/'); + + // Replace tokens. + $destination = \Drupal::token()->replace($destination, $data); + + return $settings['uri_scheme'] . '://' . $destination; + } + + /** + * Retrieves the upload validators for a file field. + * + * @return + * An array suitable for passing to file_save_upload() or the file field + * element's '#upload_validators' property. + */ + public function getUploadValidators() { + $validators = array(); + $settings = $this->getFieldSettings(); + + // Cap the upload size according to the PHP limit. + $max_filesize = parse_size(file_upload_max_size()); + if (!empty($settings['max_filesize'])) { + $max_filesize = min($max_filesize, parse_size($settings['max_filesize'])); + } + + // There is always a file size limit due to the PHP server limit. + $validators['file_validate_size'] = array($max_filesize); + + // Add the extension check if necessary. + if (!empty($settings['file_extensions'])) { + $validators['file_validate_extensions'] = array($settings['file_extensions']); + } + + return $validators; + } + +} diff --git a/core/modules/file/lib/Drupal/file/Plugin/field/widget/FileWidget.php b/core/modules/file/lib/Drupal/file/Plugin/field/widget/FileWidget.php index 245ec34..ae2f6d2 100644 --- a/core/modules/file/lib/Drupal/file/Plugin/field/widget/FileWidget.php +++ b/core/modules/file/lib/Drupal/file/Plugin/field/widget/FileWidget.php @@ -184,8 +184,6 @@ public function formElement(FieldInterface $items, $delta, array $element, $lang // The field settings include defaults for the field type. However, this // widget is a base class for other widgets (e.g., ImageWidget) that may act // on field types without these expected settings. - // @todo Add support for merging settings of base types to implementations - // of FieldDefinitionInterface::getFieldSettings(). $field_settings += array( 'display_default' => NULL, 'display_field' => NULL, @@ -204,8 +202,8 @@ public function formElement(FieldInterface $items, $delta, array $element, $lang $element_info = element_info('managed_file'); $element += array( '#type' => 'managed_file', - '#upload_location' => file_field_widget_uri($field_settings), - '#upload_validators' => file_field_widget_upload_validators($field_settings), + '#upload_location' => $items[$delta]->getUri(), + '#upload_validators' => $items[$delta]->getUploadValidators(), '#value_callback' => 'file_field_widget_value', '#process' => array_merge($element_info['#process'], array('file_field_widget_process')), '#progress_indicator' => $this->getSetting('progress_indicator'), 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 4741a73..914450f 100644 --- a/core/modules/image/image.field.inc +++ b/core/modules/image/image.field.inc @@ -6,272 +6,12 @@ */ use Drupal\Component\Utility\NestedArray; -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 = \Drupal::service('plugin.manager.entity.field.field_type')->getDefaultSettings($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' => '
', - '#field_suffix' => '
', - '#description' => t('The maximum allowed image size expressed as WIDTHxHEIGHT (e.g. 640x480). Leave blank for no restriction. If a larger image is uploaded, it will be resized to reflect the given width and height. Resizing images on upload will cause the loss of EXIF data in the image.', array('@url' => 'http://en.wikipedia.org/wiki/Exchangeable_image_file_format')), - ); - $form['max_resolution']['x'] = array( - '#type' => 'number', - '#title' => t('Maximum width'), - '#title_display' => 'invisible', - '#default_value' => $max_resolution[0], - '#min' => 1, - '#field_suffix' => ' x ', - ); - $form['max_resolution']['y'] = array( - '#type' => 'number', - '#title' => t('Maximum height'), - '#title_display' => 'invisible', - '#default_value' => $max_resolution[1], - '#min' => 1, - '#field_suffix' => ' ' . t('pixels'), - ); - - $min_resolution = explode('x', $settings['min_resolution']) + array('', ''); - $form['min_resolution'] = array( - '#type' => 'item', - '#title' => t('Minimum image resolution'), - '#element_validate' => array('_image_field_resolution_validate'), - '#weight' => 4.2, - '#field_prefix' => '
', - '#field_suffix' => '
', - '#description' => t('The minimum allowed image size expressed as WIDTHxHEIGHT (e.g. 640x480). Leave blank for no restriction. If a smaller image is uploaded, it will be rejected.'), - ); - $form['min_resolution']['x'] = array( - '#type' => 'number', - '#title' => t('Minimum width'), - '#title_display' => 'invisible', - '#default_value' => $min_resolution[0], - '#min' => 1, - '#field_suffix' => ' x ', - ); - $form['min_resolution']['y'] = array( - '#type' => 'number', - '#title' => t('Minimum height'), - '#title_display' => 'invisible', - '#default_value' => $min_resolution[1], - '#min' => 1, - '#field_suffix' => ' ' . t('pixels'), - ); - - // Remove the description option. - unset($form['description_field']); - - // Add title and alt configuration options. - $form['alt_field'] = array( - '#type' => 'checkbox', - '#title' => t('Enable Alt field'), - '#default_value' => $settings['alt_field'], - '#description' => t('The alt attribute may be used by search engines, screen readers, and when the image cannot be loaded.'), - '#weight' => 9, - ); - $form['alt_field_required'] = array( - '#type' => 'checkbox', - '#title' => t('Alt field required'), - '#default_value' => $settings['alt_field_required'], - '#weight' => 10, - '#states' => array( - 'visible' => array( - ':input[name="instance[settings][alt_field]"]' => array('checked' => TRUE), - ), - ), - ); - $form['title_field'] = array( - '#type' => 'checkbox', - '#title' => t('Enable Title field'), - '#default_value' => $settings['title_field'], - '#description' => t('The title attribute is used as a tooltip when the mouse hovers over the image.'), - '#weight' => 11, - ); - $form['title_field_required'] = array( - '#type' => 'checkbox', - '#title' => t('Title field required'), - '#default_value' => $settings['title_field_required'], - '#weight' => 12, - '#states' => array( - 'visible' => array( - ':input[name="instance[settings][title_field]"]' => array('checked' => TRUE), - ), - ), - ); - - - // Add the default image to the instance. - $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 and will override the field's default image."), - '#default_value' => empty($settings['default_image']) ? array() : array($settings['default_image']), - '#upload_location' => $field['settings']['uri_scheme'] . '://default_images/', - ); - - return $form; -} - -/** - * Element validate function for resolution fields. - */ -function _image_field_resolution_validate($element, &$form_state) { - if (!empty($element['x']['#value']) || !empty($element['y']['#value'])) { - foreach (array('x', 'y') as $dimension) { - if (!$element[$dimension]['#value']) { - form_error($element[$dimension], t('Both a height and width value must be specified in the !name field.', array('!name' => $element['#title']))); - return; - } - } - form_set_value($element, $element['x']['#value'] . 'x' . $element['y']['#value'], $form_state); - } - else { - form_set_value($element, '', $form_state); - } -} - -/** - * Implements hook_field_presave(). - */ -function image_field_presave(EntityInterface $entity, $field, $instance, $langcode, &$items) { - $image_factory = Drupal::service('image.factory'); - // Determine the dimensions if necessary. - foreach ($items as &$item) { - if (!isset($item['width']) || !isset($item['height'])) { - $image = $image_factory->get(file_load($item['target_id'])->getFileUri()); - if ($image->getExtension()) { - $item['width'] = $image->getWidth(); - $item['height'] = $image->getHeight(); - } - } - } -} - -/** - * Implements hook_field_insert(). - */ -function image_field_insert(EntityInterface $entity, $field, $instance, $langcode, &$items) { - file_field_insert($entity, $field, $instance, $langcode, $items); -} - -/** - * Implements hook_field_update(). - */ -function image_field_update(EntityInterface $entity, $field, $instance, $langcode, &$items) { - file_field_update($entity, $field, $instance, $langcode, $items); -} - -/** - * Implements hook_field_delete(). - */ -function image_field_delete(EntityInterface $entity, $field, $instance, $langcode, &$items) { - file_field_delete($entity, $field, $instance, $langcode, $items); -} - -/** - * Implements hook_field_delete_revision(). - */ -function image_field_delete_revision(EntityInterface $entity, $field, $instance, $langcode, &$items) { - file_field_delete_revision($entity, $field, $instance, $langcode, $items); -} - -/** - * Implements hook_field_is_empty(). - */ -function image_field_is_empty($item, $field_type) { - return file_field_is_empty($item, $field_type); +function image_field_info_alter(&$info) { + $info['image']['settings']['uri_scheme'] = file_default_scheme(); } /** diff --git a/core/modules/image/image.install b/core/modules/image/image.install index 39ddedf..bbeb777 100644 --- a/core/modules/image/image.install +++ b/core/modules/image/image.install @@ -25,53 +25,6 @@ function image_uninstall() { } /** - * Implements hook_field_schema(). - */ -function image_field_schema($field) { - return array( - 'columns' => array( - 'target_id' => array( - 'description' => 'The ID of the target entity.', - 'type' => 'int', - 'not null' => TRUE, - 'unsigned' => TRUE, - ), - 'alt' => array( - 'description' => "Alternative image text, for the image's 'alt' attribute.", - 'type' => 'varchar', - 'length' => 512, - 'not null' => FALSE, - ), - 'title' => array( - 'description' => "Image title text, for the image's 'title' attribute.", - 'type' => 'varchar', - 'length' => 1024, - 'not null' => FALSE, - ), - 'width' => array( - 'description' => 'The width of the image in pixels.', - 'type' => 'int', - 'unsigned' => TRUE, - ), - 'height' => array( - 'description' => 'The height of the image in pixels.', - 'type' => 'int', - 'unsigned' => TRUE, - ), - ), - 'indexes' => array( - 'target_id' => array('target_id'), - ), - 'foreign keys' => array( - 'target_id' => array( - 'table' => 'file_managed', - 'columns' => array('target_id' => 'fid'), - ), - ), - ); -} - -/** * Implements hook_requirements() to check the PHP GD Library. * * @param $phase diff --git a/core/modules/image/lib/Drupal/image/Plugin/field/field_type/ImageItem.php b/core/modules/image/lib/Drupal/image/Plugin/field/field_type/ImageItem.php new file mode 100644 index 0000000..8cec182 --- /dev/null +++ b/core/modules/image/lib/Drupal/image/Plugin/field/field_type/ImageItem.php @@ -0,0 +1,327 @@ + array( + 'target_id' => array( + 'description' => 'The ID of the target entity.', + 'type' => 'int', + 'not null' => TRUE, + 'unsigned' => TRUE, + ), + 'alt' => array( + 'description' => "Alternative image text, for the image's 'alt' attribute.", + 'type' => 'varchar', + 'length' => 512, + 'not null' => FALSE, + ), + 'title' => array( + 'description' => "Image title text, for the image's 'title' attribute.", + 'type' => 'varchar', + 'length' => 1024, + 'not null' => FALSE, + ), + 'width' => array( + 'description' => 'The width of the image in pixels.', + 'type' => 'int', + 'unsigned' => TRUE, + ), + 'height' => array( + 'description' => 'The height of the image in pixels.', + 'type' => 'int', + 'unsigned' => TRUE, + ), + ), + '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'] = 'image'; + // 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]['alt'] = array( + 'type' => 'string', + 'label' => t("Alternative image text, for the image's 'alt' attribute."), + ); + static::$propertyDefinitions[$key]['title'] = array( + 'type' => 'string', + 'label' => t("Image title text, for the image's 'title' attribute."), + ); + static::$propertyDefinitions[$key]['width'] = array( + 'type' => 'integer', + 'label' => t('The width of the image in pixels.'), + ); + static::$propertyDefinitions[$key]['height'] = array( + 'type' => 'integer', + 'label' => t('The height of the image in pixels.'), + ); + } + return static::$propertyDefinitions[$key]; + } + + /** + * {@inheritdoc} + */ + public function settingsForm(array $form, array &$form_state, $has_data) { + $element = array(); + $settings = $this->getFieldDefinition()->getField()->getFieldSettings(); + + $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' => $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. + $element['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($settings['default_image']) ? array() : array($settings['default_image']), + '#upload_location' => $settings['uri_scheme'] . '://default_images/', + ); + + return $element; + } + + /** + * {@inheritdoc} + */ + public function instanceSettingsForm(array $form, array &$form_state) { + // Get base form from FileItem::instanceSettingsForm(). + $element = parent::instanceSettingsForm($form, $form_state); + + $settings = $this->getFieldSettings(); + + // Add maximum and minimum resolution settings. + $max_resolution = explode('x', $settings['max_resolution']) + array('', ''); + $element['max_resolution'] = array( + '#type' => 'item', + '#title' => t('Maximum image resolution'), + '#element_validate' => array(array($this, 'validateResolution')), + '#weight' => 4.1, + '#field_prefix' => '
', + '#field_suffix' => '
', + '#description' => t('The maximum allowed image size expressed as WIDTHxHEIGHT (e.g. 640x480). Leave blank for no restriction. If a larger image is uploaded, it will be resized to reflect the given width and height. Resizing images on upload will cause the loss of EXIF data in the image.', array('@url' => 'http://en.wikipedia.org/wiki/Exchangeable_image_file_format')), + ); + $element['max_resolution']['x'] = array( + '#type' => 'number', + '#title' => t('Maximum width'), + '#title_display' => 'invisible', + '#default_value' => $max_resolution[0], + '#min' => 1, + '#field_suffix' => ' x ', + ); + $element['max_resolution']['y'] = array( + '#type' => 'number', + '#title' => t('Maximum height'), + '#title_display' => 'invisible', + '#default_value' => $max_resolution[1], + '#min' => 1, + '#field_suffix' => ' ' . t('pixels'), + ); + + $min_resolution = explode('x', $settings['min_resolution']) + array('', ''); + $element['min_resolution'] = array( + '#type' => 'item', + '#title' => t('Minimum image resolution'), + '#element_validate' => array(array($this, 'validateResolution')), + '#weight' => 4.2, + '#field_prefix' => '
', + '#field_suffix' => '
', + '#description' => t('The minimum allowed image size expressed as WIDTHxHEIGHT (e.g. 640x480). Leave blank for no restriction. If a smaller image is uploaded, it will be rejected.'), + ); + $element['min_resolution']['x'] = array( + '#type' => 'number', + '#title' => t('Minimum width'), + '#title_display' => 'invisible', + '#default_value' => $min_resolution[0], + '#min' => 1, + '#field_suffix' => ' x ', + ); + $element['min_resolution']['y'] = array( + '#type' => 'number', + '#title' => t('Minimum height'), + '#title_display' => 'invisible', + '#default_value' => $min_resolution[1], + '#min' => 1, + '#field_suffix' => ' ' . t('pixels'), + ); + + // Remove the description option. + unset($element['description_field']); + + // Add title and alt configuration options. + $element['alt_field'] = array( + '#type' => 'checkbox', + '#title' => t('Enable Alt field'), + '#default_value' => $settings['alt_field'], + '#description' => t('The alt attribute may be used by search engines, screen readers, and when the image cannot be loaded.'), + '#weight' => 9, + ); + $element['alt_field_required'] = array( + '#type' => 'checkbox', + '#title' => t('Alt field required'), + '#default_value' => $settings['alt_field_required'], + '#weight' => 10, + '#states' => array( + 'visible' => array( + ':input[name="instance[settings][alt_field]"]' => array('checked' => TRUE), + ), + ), + ); + $element['title_field'] = array( + '#type' => 'checkbox', + '#title' => t('Enable Title field'), + '#default_value' => $settings['title_field'], + '#description' => t('The title attribute is used as a tooltip when the mouse hovers over the image.'), + '#weight' => 11, + ); + $element['title_field_required'] = array( + '#type' => 'checkbox', + '#title' => t('Title field required'), + '#default_value' => $settings['title_field_required'], + '#weight' => 12, + '#states' => array( + 'visible' => array( + ':input[name="instance[settings][title_field]"]' => array('checked' => TRUE), + ), + ), + ); + + // Add the default image to the instance. + $element['default_image'] = array( + '#title' => t('Default image'), + '#type' => 'managed_file', + '#description' => t("If no image is uploaded, this image will be shown on display and will override the field's default image."), + '#default_value' => empty($settings['default_image']) ? array() : array($settings['default_image']), + '#upload_location' => $settings['uri_scheme'] . '://default_images/', + ); + + return $element; + } + + /** + * {@inheritdoc} + */ + public function preSave() { + $entity = $this->getRoot(); + $target_id = $this->get('target_id')->getValue(); + $width = $this->get('width')->getValue(); + $height = $this->get('height')->getValue(); + + // Determine the dimensions if necessary. + if (empty($width) || empty($height)) { + $image = \Drupal::service('image.factory')->get(file_load($target_id)->getFileUri()); + + if ($image->getExtension()) { + $this->set('width', $image->getWidth()); + $this->set('height', $image->getHeight()); + } + } + } + + /** + * Element validate function for resolution fields. + */ + public function validateResolution($element, &$form_state) { + if (!empty($element['x']['#value']) || !empty($element['y']['#value'])) { + foreach (array('x', 'y') as $dimension) { + if (!$element[$dimension]['#value']) { + form_error($element[$dimension], t('Both a height and width value must be specified in the !name field.', array('!name' => $element['#title']))); + return; + } + } + form_set_value($element, $element['x']['#value'] . 'x' . $element['y']['#value'], $form_state); + } + else { + form_set_value($element, '', $form_state); + } + } + +} diff --git a/core/modules/image/lib/Drupal/image/Type/ImageItem.php b/core/modules/image/lib/Drupal/image/Type/ImageItem.php deleted file mode 100644 index 3b86fe4..0000000 --- a/core/modules/image/lib/Drupal/image/Type/ImageItem.php +++ /dev/null @@ -1,58 +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]['alt'] = array( - 'type' => 'string', - 'label' => t("Alternative image text, for the image's 'alt' attribute."), - ); - static::$propertyDefinitions[$key]['title'] = array( - 'type' => 'string', - 'label' => t("Image title text, for the image's 'title' attribute."), - ); - static::$propertyDefinitions[$key]['width'] = array( - 'type' => 'integer', - 'label' => t('The width of the image in pixels.'), - ); - static::$propertyDefinitions[$key]['height'] = array( - 'type' => 'integer', - 'label' => t('The height of the image in pixels.'), - ); - } - return static::$propertyDefinitions[$key]; - } - -} -- 1.8.3.1