From 87c390d8f3f5dd9caf7d980477136373a7f01519 Mon Sep 17 00:00:00 2001 From: Pierre Buyle Date: Thu, 23 Jun 2011 10:43:00 +0200 Subject: [PATCH] Issue #1197450 by mongolito404: implement file_entity_entity_property_info_alter to provide metadata for the file type property. --- file_entity/file_entity.file_api.inc | 17 +++++++++++++++++ file_entity/file_entity.module | 16 ++++++++++++++++ 2 files changed, 33 insertions(+), 0 deletions(-) diff --git a/file_entity/file_entity.file_api.inc b/file_entity/file_entity.file_api.inc index c3c4b34..9149dbb 100644 --- a/file_entity/file_entity.file_api.inc +++ b/file_entity/file_entity.file_api.inc @@ -33,6 +33,23 @@ function file_info_file_types($file_type = NULL) { } /** + * Returns the file types list of options. + * + * @return + * The file type as an options array. Array keys are the file type names. + * Array values are the file type labels. + * + * @see file_info_file_types() + */ +function file_info_file_types_options_list() { + $options = array(); + foreach (file_info_file_types() as $name => $info) { + $options[$name] = $info['label']; + } + return $options; +} + +/** * Determines the file type of a passed in file object. */ function file_get_type($file) { diff --git a/file_entity/file_entity.module b/file_entity/file_entity.module index 0d5d679..e3d1d78 100644 --- a/file_entity/file_entity.module +++ b/file_entity/file_entity.module @@ -133,6 +133,22 @@ function file_entity_entity_info_alter(&$entity_info) { } /** + * Implements hook_entity_property_info_alter(). + */ +function file_entity_entity_property_info_alter(&$info) { + $properties = &$info['file']['properties']; + $properties['type'] = array( + 'label' => t("File type"), + 'type' => 'token', + 'description' => t("File type."), + 'setter callback' => 'entity_property_verbatim_set', + 'options list' => 'file_info_file_types_options_list', + 'required' => TRUE, + 'schema field' => 'type', + ); +} + +/** * Implements hook_field_extra_fields(). * * Adds 'file' as an extra field, so that its display and form component can be -- 1.7.1