Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
drupal
Commits
0b978036
Commit
0b978036
authored
Nov 29, 2009
by
Dries Buytaert
Browse files
- Patch
#613754
by yched, detour, matt2000: fixed field_info_fields().
parent
4fca5a64
Changes
2
Hide whitespace changes
Inline
Side-by-side
modules/field/field.info.inc
View file @
0b978036
...
...
@@ -451,50 +451,16 @@ function field_info_bundles($obj_type = NULL) {
}
/**
* Return a
rray of all field data, keyed by field name
.
* Return a
ll 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
F
ield
objects
. Each
F
ield
object has an additional
* property, bundles, which is an array of all the bundles to
which
* this field belongs.
* An array of
f
ield
definitions, keyd by field name
. Each
f
ield
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'
];
}
/**
...
...
modules/file/file.module
View file @
0b978036
...
...
@@ -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
));
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment