diff options
author | Dries Buytaert <dries@buytaert.net> | 2009-11-29 06:35:47 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2009-11-29 06:35:47 +0000 |
commit | 0b978036130c871362a78dccb229ee279d856006 (patch) | |
tree | befe24b8058cd73d565abe1bf59003db167d2329 | |
parent | 4fca5a6412a4315fcc6f1071bff820d20f94ee99 (diff) | |
download | brdo-0b978036130c871362a78dccb229ee279d856006.tar.gz brdo-0b978036130c871362a78dccb229ee279d856006.tar.bz2 |
- Patch #613754 by yched, detour, matt2000: fixed field_info_fields().
-rw-r--r-- | modules/field/field.info.inc | 48 | ||||
-rw-r--r-- | modules/file/file.module | 61 |
2 files changed, 44 insertions, 65 deletions
diff --git a/modules/field/field.info.inc b/modules/field/field.info.inc index 366a009eb..fe2af51a8 100644 --- a/modules/field/field.info.inc +++ b/modules/field/field.info.inc @@ -451,50 +451,16 @@ function field_info_bundles($obj_type = NULL) { } /** - * Return array of all field data, keyed by field name. + * Return all field efinitions. * - * @param $bundle_type - * (optional) The bundle type on which to filter the list of fields. In the - * case of nodes, this is the node type. - * @param $field - * (optional) A field array or name on which to filter the list. - * @param $field_type - * (optional) A field type on which to filter the list. * @return - * An array of Field objects. Each Field object has an additional - * property, bundles, which is an array of all the bundles to which - * this field belongs. + * An array of field definitions, keyd by field name. Each field has an + * additional property, 'bundles', which is an array of all the bundles to + * which this field belongs. */ -function field_info_fields($bundle_type = NULL, $field = NULL, $field_type = NULL) { - // Build the list of fields to be used for retrieval. - if (isset($field)) { - if (is_string($field)) { - $field = field_info_field($field); - } - $fields = array($field['field_name'] => $field); - } - elseif (isset($bundle_type)) { - $instances = field_info_instances($bundle_type); - $fields = array(); - foreach ($instances as $field_name => $instance) { - $fields[$field_name] = field_info_field($field_name); - } - } - else { - $info = _field_info_collate_fields(); - $fields = $info['fields']; - } - - // If a field type was given, filter the list down to fields of that type. - if (isset($field_type)) { - foreach ($fields as $key => $field) { - if ($field['type'] != $field_type) { - unset($fields[$key]); - } - } - } - - return $fields; +function field_info_fields() { + $info = _field_info_collate_fields(); + return $info['fields']; } /** diff --git a/modules/file/file.module b/modules/file/file.module index 36357e893..1d8d0b57d 100644 --- a/modules/file/file.module +++ b/modules/file/file.module @@ -857,36 +857,49 @@ function file_icon_map($file) { * An integer value. */ function file_get_file_reference_count($file, $field = NULL, $field_type = 'file') { - $fields = field_info_fields(NULL, $field, $field_type); + // Determine the collection of fields to check. + if (isset($field)) { + // Support $field as 'field name'. + if (is_string($field)) { + $field = field_info_field($field); + } + $fields = array($field['field_name'] => $field); + } + else { + $fields = field_info_fields(); + } + $types = entity_get_info(); $reference_count = 0; foreach ($fields as $field) { - // TODO: Use a more efficient mechanism rather than actually retrieving - // all the references themselves, such as using a COUNT() query. - $references = file_get_file_references($file, $field, FIELD_LOAD_REVISION, $field_type); - foreach ($references as $obj_type => $type_references) { - $reference_count += count($type_references); - } + if (empty($field_type) || $field['type'] == $field_type) { + // TODO: Use a more efficient mechanism rather than actually retrieving + // all the references themselves, such as using a COUNT() query. + $references = file_get_file_references($file, $field, FIELD_LOAD_REVISION, $field_type); + foreach ($references as $obj_type => $type_references) { + $reference_count += count($type_references); + } - // If a field_name is present in the file object, the file is being deleted - // from this field. - if (isset($file->file_field_name) && $field['field_name'] == $file->file_field_name) { - // If deleting the entire piece of content, decrement references. - if (isset($file->file_field_type) && isset($file->file_field_id)) { - if ($file->file_field_type == $obj_type) { - $info = entity_get_info($obj_type); - $id = $types[$obj_type]['object keys']['id']; - foreach ($type_references as $reference) { - if ($file->file_field_id == $reference->$id) { - $reference_count--; + // If a field_name is present in the file object, the file is being deleted + // from this field. + if (isset($file->file_field_name) && $field['field_name'] == $file->file_field_name) { + // If deleting the entire piece of content, decrement references. + if (isset($file->file_field_type) && isset($file->file_field_id)) { + if ($file->file_field_type == $obj_type) { + $info = entity_get_info($obj_type); + $id = $types[$obj_type]['object keys']['id']; + foreach ($type_references as $reference) { + if ($file->file_field_id == $reference->$id) { + $reference_count--; + } } } } - } - // Otherwise we're just deleting a single reference in this field. - else { - $reference_count--; + // Otherwise we're just deleting a single reference in this field. + else { + $reference_count--; + } } } } @@ -915,10 +928,10 @@ function file_get_file_reference_count($file, $field = NULL, $field_type = 'file */ function file_get_file_references($file, $field = NULL, $age = FIELD_LOAD_REVISION, $field_type = 'file') { $references = drupal_static(__FUNCTION__, array()); - $fields = field_info_fields(NULL, $field, $field_type); + $fields = isset($field) ? array($field['field_name'] => $field) : field_info_fields(); foreach ($fields as $field_name => $file_field) { - if (!isset($references[$field_name])) { + if ((empty($field_type) || $field['type'] == $field_type) && !isset($references[$field_name])) { // Get each time this file is used within a field. $cursor = 0; $references[$field_name] = field_attach_query($file_field['id'], array(array('fid', $file->fid)), array('limit' => FIELD_QUERY_NO_LIMIT, 'cursor' => &$cursor, 'age'=> $age)); |