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
7562a8ef
Commit
7562a8ef
authored
Feb 11, 2010
by
Angie Byron
Browse files
#707724
by chx: Rename confusing arguments in field/entity APIs.
parent
52195a6b
Changes
32
Expand all
Hide whitespace changes
Inline
Side-by-side
modules/field/field.api.php
View file @
7562a8ef
This diff is collapsed.
Click to expand it.
modules/field/field.attach.inc
View file @
7562a8ef
This diff is collapsed.
Click to expand it.
modules/field/field.crud.inc
View file @
7562a8ef
...
...
@@ -41,7 +41,7 @@
* - field_name (string)
* The name of the field. Each field name is unique within Field API.
* When a field is attached to an object, the field's data is stored
* in $
object
->$field_name.
* in $
entity
->$field_name.
* - type (string)
* The type of the field, such as 'text' or 'image'. Field types
* are defined by modules that implement hook_field_info().
...
...
@@ -553,9 +553,9 @@ function field_delete_field($field_name) {
// Delete all non-deleted instances.
$field
=
field_info_field
(
$field_name
);
if
(
isset
(
$field
[
'bundles'
]))
{
foreach
(
$field
[
'bundles'
]
as
$
obj
_type
=>
$bundles
)
{
foreach
(
$field
[
'bundles'
]
as
$
entity
_type
=>
$bundles
)
{
foreach
(
$bundles
as
$bundle
)
{
$instance
=
field_info_instance
(
$
obj
_type
,
$field_name
,
$bundle
);
$instance
=
field_info_instance
(
$
entity
_type
,
$field_name
,
$bundle
);
field_delete_instance
(
$instance
);
}
}
...
...
@@ -786,7 +786,7 @@ function _field_write_instance($instance, $update = FALSE) {
* This function will not return deleted instances. Use
* field_read_instances() instead for this purpose.
*
* @param $
obj
_type
* @param $
entity
_type
* The type of object to which the field is bound.
* @param $field_name
* The field name to read.
...
...
@@ -801,8 +801,8 @@ function _field_write_instance($instance, $update = FALSE) {
* @return
* An instance structure, or FALSE.
*/
function
field_read_instance
(
$
obj
_type
,
$field_name
,
$bundle
,
$include_additional
=
array
())
{
$instances
=
field_read_instances
(
array
(
'object_type'
=>
$
obj
_type
,
'field_name'
=>
$field_name
,
'bundle'
=>
$bundle
),
$include_additional
);
function
field_read_instance
(
$
entity
_type
,
$field_name
,
$bundle
,
$include_additional
=
array
())
{
$instances
=
field_read_instances
(
array
(
'object_type'
=>
$
entity
_type
,
'field_name'
=>
$field_name
,
'bundle'
=>
$bundle
),
$include_additional
);
return
$instances
?
current
(
$instances
)
:
FALSE
;
}
...
...
@@ -984,14 +984,14 @@ function field_purge_batch($batch_size) {
$field
=
field_info_field_by_id
(
$instance
[
'field_id'
]);
// Retrieve some pseudo-objects.
$
obj
_types
=
field_attach_query
(
$instance
[
'field_id'
],
array
(
array
(
'bundle'
,
$instance
[
'bundle'
]),
array
(
'deleted'
,
1
)),
array
(
'limit'
=>
$batch_size
));
$
entity
_types
=
field_attach_query
(
$instance
[
'field_id'
],
array
(
array
(
'bundle'
,
$instance
[
'bundle'
]),
array
(
'deleted'
,
1
)),
array
(
'limit'
=>
$batch_size
));
if
(
count
(
$
obj
_types
)
>
0
)
{
if
(
count
(
$
entity
_types
)
>
0
)
{
// Field data for the instance still exists.
foreach
(
$
obj
_types
as
$
obj
_type
=>
$
object
s
)
{
field_attach_load
(
$
obj
_type
,
$
object
s
,
FIELD_LOAD_CURRENT
,
array
(
'field_id'
=>
$field
[
'id'
],
'deleted'
=>
1
));
foreach
(
$
entity
_types
as
$
entity
_type
=>
$
entitie
s
)
{
field_attach_load
(
$
entity
_type
,
$
entitie
s
,
FIELD_LOAD_CURRENT
,
array
(
'field_id'
=>
$field
[
'id'
],
'deleted'
=>
1
));
foreach
(
$
object
s
as
$id
=>
$
object
)
{
foreach
(
$
entitie
s
as
$id
=>
$
entity
)
{
// field_attach_query() may return more results than we asked for.
// Stop when he have done our batch size.
if
(
$batch_size
--
<=
0
)
{
...
...
@@ -999,7 +999,7 @@ function field_purge_batch($batch_size) {
}
// Purge the data for the object.
field_purge_data
(
$
obj
_type
,
$
object
,
$field
,
$instance
);
field_purge_data
(
$
entity
_type
,
$
entity
,
$field
,
$instance
);
}
}
}
...
...
@@ -1027,28 +1027,28 @@ function field_purge_batch($batch_size) {
* to a single field. The object itself is not being deleted, and it is quite
* possible that other field data will remain attached to it.
*
* @param $
obj
_type
* The type of $
object
; e.g. 'node' or 'user'.
* @param $
object
* @param $
entity
_type
* The type of $
entity
; e.g. 'node' or 'user'.
* @param $
entity
* The pseudo-object whose field data to delete.
* @param $field
* The (possibly deleted) field whose data is being purged.
* @param $instance
* The deleted field instance whose data is being purged.
*/
function
field_purge_data
(
$
obj
_type
,
$
object
,
$field
,
$instance
)
{
function
field_purge_data
(
$
entity
_type
,
$
entity
,
$field
,
$instance
)
{
// Each field type's hook_field_delete() only expects to operate on a single
// field at a time, so we can use it as-is for purging.
$options
=
array
(
'field_id'
=>
$instance
[
'field_id'
],
'deleted'
=>
TRUE
);
_field_invoke
(
'delete'
,
$
obj
_type
,
$
object
,
$dummy
,
$dummy
,
$options
);
_field_invoke
(
'delete'
,
$
entity
_type
,
$
entity
,
$dummy
,
$dummy
,
$options
);
// Tell the field storage system to purge the data.
module_invoke
(
$field
[
'storage'
][
'module'
],
'field_storage_purge'
,
$
obj
_type
,
$
object
,
$field
,
$instance
);
module_invoke
(
$field
[
'storage'
][
'module'
],
'field_storage_purge'
,
$
entity
_type
,
$
entity
,
$field
,
$instance
);
// Let other modules act on purging the data.
foreach
(
module_implements
(
'field_attach_purge'
)
as
$module
)
{
$function
=
$module
.
'_field_attach_purge'
;
$function
(
$
obj
_type
,
$
object
,
$field
,
$instance
);
$function
(
$
entity
_type
,
$
entity
,
$field
,
$instance
);
}
}
...
...
modules/field/field.default.inc
View file @
7562a8ef
...
...
@@ -11,7 +11,7 @@
* the corresponding field_attach_[operation]() function.
*/
function
field_default_extract_form_values
(
$
obj
_type
,
$
object
,
$field
,
$instance
,
$langcode
,
&
$items
,
$form
,
&
$form_state
)
{
function
field_default_extract_form_values
(
$
entity
_type
,
$
entity
,
$field
,
$instance
,
$langcode
,
&
$items
,
$form
,
&
$form_state
)
{
$field_name
=
$field
[
'field_name'
];
if
(
isset
(
$form_state
[
'values'
][
$field_name
][
$langcode
]))
{
...
...
@@ -29,18 +29,18 @@ function field_default_extract_form_values($obj_type, $object, $field, $instance
*
* @see _hook_field_validate()
*
* @param $
obj
_type
* The type of $
object
.
* @param $
object
* @param $
entity
_type
* The type of $
entity
.
* @param $
entity
* The object for the operation.
* @param $field
* The field structure for the operation.
* @param $instance
* The instance structure for $field on $
object
's bundle.
* The instance structure for $field on $
entity
's bundle.
* @param $langcode
* The language associated to $items.
* @param $items
* $
object
->{$field['field_name']}[$langcode], or an empty array if unset.
* $
entity
->{$field['field_name']}[$langcode], or an empty array if unset.
* @param $errors
* The array of errors, keyed by field name and by value delta, that have
* already been reported for the object. The function should add its errors
...
...
@@ -49,7 +49,7 @@ function field_default_extract_form_values($obj_type, $object, $field, $instance
* - 'error': an error code (should be a string, prefixed with the module name)
* - 'message': the human readable message to be displayed.
*/
function
field_default_validate
(
$
obj
_type
,
$
object
,
$field
,
$instance
,
$langcode
,
$items
,
&
$errors
)
{
function
field_default_validate
(
$
entity
_type
,
$
entity
,
$field
,
$instance
,
$langcode
,
$items
,
&
$errors
)
{
// Filter out empty values.
$items
=
_field_filter_items
(
$field
,
$items
);
...
...
@@ -64,7 +64,7 @@ function field_default_validate($obj_type, $object, $field, $instance, $langcode
}
}
function
field_default_submit
(
$
obj
_type
,
$
object
,
$field
,
$instance
,
$langcode
,
&
$items
,
$form
,
&
$form_state
)
{
function
field_default_submit
(
$
entity
_type
,
$
entity
,
$field
,
$instance
,
$langcode
,
&
$items
,
$form
,
&
$form_state
)
{
$field_name
=
$field
[
'field_name'
];
// Reorder items to account for drag-n-drop reordering.
...
...
@@ -79,29 +79,29 @@ function field_default_submit($obj_type, $object, $field, $instance, $langcode,
/**
* Default field 'insert' operation.
*
* Insert default value if no $
object
->$field_name entry was provided.
* Insert default value if no $
entity
->$field_name entry was provided.
* This can happen with programmatic saves, or on form-based creation where
* the current user doesn't have 'edit' permission for the field.
*/
function
field_default_insert
(
$
obj
_type
,
$
object
,
$field
,
$instance
,
$langcode
,
&
$items
)
{
// _field_invoke() populates $items with an empty array if the $
object
has no
// entry for the field, so we check on the $
object
itself.
function
field_default_insert
(
$
entity
_type
,
$
entity
,
$field
,
$instance
,
$langcode
,
&
$items
)
{
// _field_invoke() populates $items with an empty array if the $
entity
has no
// entry for the field, so we check on the $
entity
itself.
// We also check that the current field translation is actually defined before
// assigning it a default value. This way we ensure that only the intended
// languages get a default value. Otherwise we could have default values for
// not yet open languages.
if
(
empty
(
$
object
)
||
!
property_exists
(
$
object
,
$field
[
'field_name'
])
||
(
isset
(
$
object
->
{
$field
[
'field_name'
]}[
$langcode
])
&&
count
(
$
object
->
{
$field
[
'field_name'
]}[
$langcode
])
==
0
))
{
$items
=
field_get_default_value
(
$
obj
_type
,
$
object
,
$field
,
$instance
,
$langcode
);
if
(
empty
(
$
entity
)
||
!
property_exists
(
$
entity
,
$field
[
'field_name'
])
||
(
isset
(
$
entity
->
{
$field
[
'field_name'
]}[
$langcode
])
&&
count
(
$
entity
->
{
$field
[
'field_name'
]}[
$langcode
])
==
0
))
{
$items
=
field_get_default_value
(
$
entity
_type
,
$
entity
,
$field
,
$instance
,
$langcode
);
}
}
/**
* Invokes hook_field_formatter_prepare_view() on the relevant formatters.
*
* @param $
obj
_type
* The type of $
object
; e.g. 'node' or 'user'.
* @param $
object
s
* @param $
entity
_type
* The type of $
entity
; e.g. 'node' or 'user'.
* @param $
entitie
s
* An array of objects being displayed, keyed by object id.
* @param $field
* The field structure for the operation.
...
...
@@ -118,7 +118,7 @@ function field_default_insert($obj_type, $object, $field, $instance, $langcode,
* - or an array of display settings to use for display, as found in the
* 'display' entry of $instance definitions.
*/
function
field_default_prepare_view
(
$
obj
_type
,
$
object
s
,
$field
,
$instances
,
$langcode
,
&
$items
,
$display
)
{
function
field_default_prepare_view
(
$
entity
_type
,
$
entitie
s
,
$field
,
$instances
,
$langcode
,
&
$items
,
$display
)
{
// Group objects, instances and items by formatter module.
$modules
=
array
();
foreach
(
$instances
as
$id
=>
$instance
)
{
...
...
@@ -126,7 +126,7 @@ function field_default_prepare_view($obj_type, $objects, $field, $instances, $la
if
(
$display
[
'type'
]
!==
'hidden'
)
{
$module
=
$display
[
'module'
];
$modules
[
$module
]
=
$module
;
$grouped_objects
[
$module
][
$id
]
=
$
object
s
[
$id
];
$grouped_objects
[
$module
][
$id
]
=
$
entitie
s
[
$id
];
$grouped_instances
[
$module
][
$id
]
=
$instance
;
$grouped_displays
[
$module
][
$id
]
=
$display
;
// hook_field_formatter_prepare_view() alters $items by reference.
...
...
@@ -138,7 +138,7 @@ function field_default_prepare_view($obj_type, $objects, $field, $instances, $la
// Invoke hook_field_formatter_prepare_view().
$function
=
$module
.
'_field_formatter_prepare_view'
;
if
(
function_exists
(
$function
))
{
$function
(
$
obj
_type
,
$grouped_objects
[
$module
],
$field
,
$grouped_instances
[
$module
],
$langcode
,
$grouped_items
[
$module
],
$grouped_displays
[
$module
]);
$function
(
$
entity
_type
,
$grouped_objects
[
$module
],
$field
,
$grouped_instances
[
$module
],
$langcode
,
$grouped_items
[
$module
],
$grouped_displays
[
$module
]);
}
}
}
...
...
@@ -146,9 +146,9 @@ function field_default_prepare_view($obj_type, $objects, $field, $instances, $la
/**
* Builds a renderable array for field values.
*
* @param $
obj
_type
* The type of $
object
; e.g. 'node' or 'user'.
* @param $
object
s
* @param $
entity
_type
* The type of $
entity
; e.g. 'node' or 'user'.
* @param $
entitie
s
* An array of objects being displayed, keyed by object id.
* @param $field
* The field structure for the operation.
...
...
@@ -165,8 +165,8 @@ function field_default_prepare_view($obj_type, $objects, $field, $instances, $la
* - or an array of custom display settings, as found in the 'display' entry
* of $instance definitions.
*/
function
field_default_view
(
$
obj
_type
,
$
object
,
$field
,
$instance
,
$langcode
,
$items
,
$display
)
{
list
(
$id
,
$vid
,
$bundle
)
=
entity_extract_ids
(
$
obj
_type
,
$
object
);
function
field_default_view
(
$
entity
_type
,
$
entity
,
$field
,
$instance
,
$langcode
,
$items
,
$display
)
{
list
(
$id
,
$vid
,
$bundle
)
=
entity_extract_ids
(
$
entity
_type
,
$
entity
);
$addition
=
array
();
...
...
@@ -189,23 +189,23 @@ function field_default_view($obj_type, $object, $field, $instance, $langcode, $i
// performance impact on pages with many fields and values.
$function
=
$display
[
'module'
]
.
'_field_formatter_view'
;
if
(
function_exists
(
$function
))
{
$elements
=
$function
(
$
obj
_type
,
$
object
,
$field
,
$instance
,
$langcode
,
$items
,
$display
);
$elements
=
$function
(
$
entity
_type
,
$
entity
,
$field
,
$instance
,
$langcode
,
$items
,
$display
);
if
(
$elements
)
{
$info
=
array
(
'#theme'
=>
'field'
,
'#weight'
=>
$display
[
'weight'
],
'#title'
=>
t
(
$instance
[
'label'
]),
'#access'
=>
field_access
(
'view'
,
$field
,
$
obj
_type
,
$
object
),
'#access'
=>
field_access
(
'view'
,
$field
,
$
entity
_type
,
$
entity
),
'#label_display'
=>
$display
[
'label'
],
'#view_mode'
=>
$view_mode
,
'#language'
=>
$langcode
,
'#field_name'
=>
$field
[
'field_name'
],
'#field_type'
=>
$field
[
'type'
],
'#field_translatable'
=>
$field
[
'translatable'
],
'#object_type'
=>
$
obj
_type
,
'#object_type'
=>
$
entity
_type
,
'#bundle'
=>
$bundle
,
'#object'
=>
$
object
,
'#object'
=>
$
entity
,
'#items'
=>
$items
,
'#formatter'
=>
$display
[
'type'
]
);
...
...
@@ -218,10 +218,10 @@ function field_default_view($obj_type, $object, $field, $instance, $langcode, $i
return
$addition
;
}
function
field_default_prepare_translation
(
$
obj
_type
,
$
object
,
$field
,
$instance
,
$langcode
,
&
$items
)
{
function
field_default_prepare_translation
(
$
entity
_type
,
$
entity
,
$field
,
$instance
,
$langcode
,
&
$items
)
{
$addition
=
array
();
if
(
isset
(
$
object
->
translation_source
->
$field
[
'field_name'
]))
{
$addition
[
$field
[
'field_name'
]]
=
$
object
->
translation_source
->
$field
[
'field_name'
];
if
(
isset
(
$
entity
->
translation_source
->
$field
[
'field_name'
]))
{
$addition
[
$field
[
'field_name'
]]
=
$
entity
->
translation_source
->
$field
[
'field_name'
];
}
return
$addition
;
}
modules/field/field.form.inc
View file @
7562a8ef
...
...
@@ -9,11 +9,11 @@
/**
* Create a separate form element for each field.
*/
function
field_default_form
(
$
obj
_type
,
$
object
,
$field
,
$instance
,
$langcode
,
$items
,
&
$form
,
&
$form_state
,
$get_delta
=
NULL
)
{
function
field_default_form
(
$
entity
_type
,
$
entity
,
$field
,
$instance
,
$langcode
,
$items
,
&
$form
,
&
$form_state
,
$get_delta
=
NULL
)
{
// This could be called with no object, as when a UI module creates a
// dummy form to set default values.
if
(
$
object
)
{
list
(
$id
,
,
)
=
entity_extract_ids
(
$
obj
_type
,
$
object
);
if
(
$
entity
)
{
list
(
$id
,
,
)
=
entity_extract_ids
(
$
entity
_type
,
$
entity
);
}
$field_name
=
$field
[
'field_name'
];
...
...
@@ -31,12 +31,12 @@ function field_default_form($obj_type, $object, $field, $instance, $langcode, $i
// Populate widgets with default values when creating a new object.
if
(
empty
(
$items
)
&&
empty
(
$id
))
{
$items
=
field_get_default_value
(
$
obj
_type
,
$
object
,
$field
,
$instance
,
$langcode
);
$items
=
field_get_default_value
(
$
entity
_type
,
$
entity
,
$field
,
$instance
,
$langcode
);
}
// Collect widget elements.
$elements
=
array
();
if
(
field_access
(
'edit'
,
$field
,
$
obj
_type
,
$
object
))
{
if
(
field_access
(
'edit'
,
$field
,
$
entity
_type
,
$
entity
))
{
// If field module handles multiple values for this form element, and we
// are displaying an individual element, process the multiple value form.
if
(
!
isset
(
$get_delta
)
&&
field_behaviors_widget
(
'multiple values'
,
$instance
)
==
FIELD_BEHAVIOR_DEFAULT
)
{
...
...
@@ -325,7 +325,7 @@ function field_form_element_after_build($element, &$form_state) {
/**
* Transfer field-level validation errors to widgets.
*/
function
field_default_form_errors
(
$
obj
_type
,
$
object
,
$field
,
$instance
,
$langcode
,
$items
,
$form
,
&
$form_state
)
{
function
field_default_form_errors
(
$
entity
_type
,
$
entity
,
$field
,
$instance
,
$langcode
,
$items
,
$form
,
&
$form_state
)
{
$field_name
=
$field
[
'field_name'
];
$field_info
=
$form_state
[
'field'
][
$field_name
][
$langcode
];
...
...
modules/field/field.info.inc
View file @
7562a8ef
...
...
@@ -208,9 +208,9 @@ function _field_info_collate_fields($reset = FALSE) {
// Populate 'instances'. Only non-deleted instances are considered.
$info
[
'instances'
]
=
array
();
foreach
(
field_info_bundles
()
as
$
obj
_type
=>
$bundles
)
{
foreach
(
field_info_bundles
()
as
$
entity
_type
=>
$bundles
)
{
foreach
(
$bundles
as
$bundle
=>
$bundle_info
)
{
$info
[
'instances'
][
$
obj
_type
][
$bundle
]
=
array
();
$info
[
'instances'
][
$
entity
_type
][
$bundle
]
=
array
();
}
}
foreach
(
$definitions
[
'instances'
]
as
$instance
)
{
...
...
@@ -481,19 +481,19 @@ function field_info_storage_types($storage_type = NULL) {
/**
* Returns information about existing bundles.
*
* @param $
obj
_type
* @param $
entity
_type
* The type of object; e.g. 'node' or 'user'.
*
* @return
* An array of bundles for the $
obj
_type keyed by bundle name,
* or, if no $
obj
_type was provided, the array of all existing bundles,
* An array of bundles for the $
entity
_type keyed by bundle name,
* or, if no $
entity
_type was provided, the array of all existing bundles,
* keyed by object type.
*/
function
field_info_bundles
(
$
obj
_type
=
NULL
)
{
function
field_info_bundles
(
$
entity
_type
=
NULL
)
{
$info
=
entity_get_info
();
if
(
$
obj
_type
)
{
return
isset
(
$info
[
$
obj
_type
][
'bundles'
])
?
$info
[
$
obj
_type
][
'bundles'
]
:
array
();
if
(
$
entity
_type
)
{
return
isset
(
$info
[
$
entity
_type
][
'bundles'
])
?
$info
[
$
entity
_type
][
'bundles'
]
:
array
();
}
$bundles
=
array
();
...
...
@@ -561,27 +561,27 @@ function field_info_field_by_id($field_id) {
/**
* Retrieves information about field instances.
*
* @param $
obj
_type
* @param $
entity
_type
* The object type for which to return instances.
* @param $bundle_name
* The bundle name for which to return instances.
*
* @return
* If $
obj
_type is not set, return all instances keyed by object type and
* bundle name. If $
obj
_type is set, return all instances for that object
* type, keyed by bundle name. If $
obj
_type and $bundle_name are set, return
* If $
entity
_type is not set, return all instances keyed by object type and
* bundle name. If $
entity
_type is set, return all instances for that object
* type, keyed by bundle name. If $
entity
_type and $bundle_name are set, return
* all instances for that bundle.
*/
function
field_info_instances
(
$
obj
_type
=
NULL
,
$bundle_name
=
NULL
)
{
function
field_info_instances
(
$
entity
_type
=
NULL
,
$bundle_name
=
NULL
)
{
$info
=
_field_info_collate_fields
();
if
(
!
isset
(
$
obj
_type
))
{
if
(
!
isset
(
$
entity
_type
))
{
return
$info
[
'instances'
];
}
if
(
!
isset
(
$bundle_name
))
{
return
$info
[
'instances'
][
$
obj
_type
];
return
$info
[
'instances'
][
$
entity
_type
];
}
if
(
isset
(
$info
[
'instances'
][
$
obj
_type
][
$bundle_name
]))
{
return
$info
[
'instances'
][
$
obj
_type
][
$bundle_name
];
if
(
isset
(
$info
[
'instances'
][
$
entity
_type
][
$bundle_name
]))
{
return
$info
[
'instances'
][
$
entity
_type
][
$bundle_name
];
}
return
array
();
}
...
...
@@ -589,17 +589,17 @@ function field_info_instances($obj_type = NULL, $bundle_name = NULL) {
/**
* Returns an array of instance data for a specific field and bundle.
*
* @param $
obj
_type
* @param $
entity
_type
* The object type for the instance.
* @param $field_name
* The field name for the instance.
* @param $bundle_name
* The bundle name for the instance.
*/
function
field_info_instance
(
$
obj
_type
,
$field_name
,
$bundle_name
)
{
function
field_info_instance
(
$
entity
_type
,
$field_name
,
$bundle_name
)
{
$info
=
_field_info_collate_fields
();
if
(
isset
(
$info
[
'instances'
][
$
obj
_type
][
$bundle_name
][
$field_name
]))
{
return
$info
[
'instances'
][
$
obj
_type
][
$bundle_name
][
$field_name
];
if
(
isset
(
$info
[
'instances'
][
$
entity
_type
][
$bundle_name
][
$field_name
]))
{
return
$info
[
'instances'
][
$
entity
_type
][
$bundle_name
][
$field_name
];
}
}
...
...
modules/field/field.module
View file @
7562a8ef
...
...
@@ -274,9 +274,9 @@ function field_associate_fields($module) {
/**
* Helper function to get the default value for a field on an object.
*
* @param $
obj
_type
* The type of $
object
; e.g. 'node' or 'user'.
* @param $
object
* @param $
entity
_type
* The type of $
entity
; e.g. 'node' or 'user'.
* @param $
entity
* The object for the operation.
* @param $field
* The field structure.
...
...
@@ -285,12 +285,12 @@ function field_associate_fields($module) {
* @param $langcode
* The field language to fill-in with the default value.
*/
function
field_get_default_value
(
$
obj
_type
,
$
object
,
$field
,
$instance
,
$langcode
=
NULL
)
{
function
field_get_default_value
(
$
entity
_type
,
$
entity
,
$field
,
$instance
,
$langcode
=
NULL
)
{
$items
=
array
();
if
(
!
empty
(
$instance
[
'default_value_function'
]))
{
$function
=
$instance
[
'default_value_function'
];
if
(
function_exists
(
$function
))
{
$items
=
$function
(
$
obj
_type
,
$
object
,
$field
,
$instance
,
$langcode
);
$items
=
$function
(
$
entity
_type
,
$
entity
,
$field
,
$instance
,
$langcode
);
}
}
elseif
(
!
empty
(
$instance
[
'default_value'
]))
{
...
...
@@ -367,14 +367,14 @@ function _field_sort_items_value_helper($a, $b) {
/**
* Registry of pseudo-field components in a given bundle.
*
* @param $
obj
_type
* The type of $
object
; e.g. 'node' or 'user'.
* @param $
entity
_type
* The type of $
entity
; e.g. 'node' or 'user'.
* @param $bundle
* The bundle name.
* @return
* The array of pseudo-field elements in the bundle.
*/
function
field_extra_fields
(
$
obj
_type
,
$bundle
)
{
function
field_extra_fields
(
$
entity
_type
,
$bundle
)
{
$info
=
&
drupal_static
(
__FUNCTION__
,
array
());
if
(
empty
(
$info
))
{
...
...
@@ -384,25 +384,25 @@ function field_extra_fields($obj_type, $bundle) {
// Add saved weights. The array is keyed by object type, bundle and
// element name.
$extra_weights
=
variable_get
(
'field_extra_weights'
,
array
());
foreach
(
$extra_weights
as
$
obj
_type_name
=>
$bundles
)
{
foreach
(
$extra_weights
as
$
entity
_type_name
=>
$bundles
)
{
foreach
(
$bundles
as
$bundle_name
=>
$weights
)
{
foreach
(
$weights
as
$key
=>
$value
)
{
if
(
isset
(
$info
[
$
obj
_type_name
][
$bundle_name
][
$key
]))
{
$info
[
$
obj
_type_name
][
$bundle_name
][
$key
][
'weight'
]
=
$value
;
if
(
isset
(
$info
[
$
entity
_type_name
][
$bundle_name
][
$key
]))
{
$info
[
$
entity
_type_name
][
$bundle_name
][
$key
][
'weight'
]
=
$value
;
}
}
}
}
}
return
isset
(
$info
[
$
obj
_type
][
$bundle
])
?
$info
[
$
obj
_type
][
$bundle
]
:
array
();
return
isset
(
$info
[
$
entity
_type
][
$bundle
])
?
$info
[
$
entity
_type
][
$bundle
]
:
array
();
}
/**
* Retrieve the user-defined weight for a 'pseudo-field' component.
*
* @param $
obj
_type
* The type of $
object
; e.g. 'node' or 'user'.
* @param $
entity
_type
* The type of $
entity
; e.g. 'node' or 'user'.
* @param $bundle
* The bundle name.
* @param $pseudo_field
...
...
@@ -411,8 +411,8 @@ function field_extra_fields($obj_type, $bundle) {
* The weight for the 'pseudo-field', respecting the user settings stored by
* field.module.
*/
function
field_extra_field_weight
(
$
obj
_type
,
$bundle
,
$pseudo_field
)
{
$extra
=
field_extra_fields
(
$
obj
_type
,
$bundle
);
function
field_extra_field_weight
(
$
entity
_type
,
$bundle
,
$pseudo_field
)
{
$extra
=
field_extra_fields
(
$
entity
_type
,
$bundle
);
if
(
isset
(
$extra
[
$pseudo_field
]))
{
return
$extra
[
$pseudo_field
][
'weight'
];
}
...
...
@@ -499,17 +499,17 @@ function _field_filter_xss_display_allowed_tags() {
* It will have been passed through the necessary check_plain() or check_markup()
* functions as necessary.
*/
function
field_format
(
$
obj
_type
,
$
object
,
$field
,
$item
,
$formatter_type
=
NULL
,
$formatter_settings
=
array
())
{
function
field_format
(
$
entity
_type
,
$
entity
,
$field
,
$item
,
$formatter_type
=
NULL
,
$formatter_settings
=
array
())
{
if
(
!
is_array
(
$field
))
{
$field
=
field_info_field
(
$field
);
}
if
(
field_access
(
'view'
,
$field
,
$
obj
_type
,
$
object
))
{
if
(
field_access
(
'view'
,
$field
,
$
entity
_type
,
$
entity
))
{
$field_type
=
field_info_field_types
(
$field
[
'type'
]);
// We need $field, $instance, $
obj
_type, $
object
to be able to display a value...
list
(,
,
$bundle
)
=
entity_extract_ids
(
$
obj
_type
,
$
object
);
$instance
=
field_info_instance
(
$
obj
_type
,
$field
[
'field_name'
],
$bundle
);
// We need $field, $instance, $
entity
_type, $
entity
to be able to display a value...
list
(,
,
$bundle
)
=
entity_extract_ids
(
$
entity
_type
,
$
entity
);
$instance
=
field_info_instance
(
$
entity
_type
,
$field
[
'field_name'
],
$bundle
);
$display
=
array
(
'type'
=>
$formatter_type
?
$formatter_type
:
$field_type
[
'default_formatter'
],
...
...
@@ -523,12 +523,12 @@ function field_format($obj_type, $object, $field, $item, $formatter_type = NULL,
$element
=
array
(
'#theme'
=>
$theme
,
'#field_name'
=>
$field
[
'field_name'
],
'#object_type'
=>
$
obj
_type
,
'#object_type'
=>
$
entity
_type
,
'#bundle'
=>
$bundle
,
'#formatter'
=>
$display
[
'type'
],
'#settings'
=>
$display
[
'settings'
],
'#object'
=>
$
object
,
'#object_type'
=>
$
obj
_type
,
'#object'
=>
$
entity
,
'#object_type'
=>
$
entity
_type
,
'#delta'
=>
isset
(
$item
[
'#delta'
])
?
$item
[
'#delta'
]
:
NULL
,
);
...
...
@@ -539,7 +539,7 @@ function field_format($obj_type, $object, $field, $item, $formatter_type = NULL,
$items
=
array
(
$item
);
$function
=
$field
[
'module'
]
.
'_field_sanitize'
;
if
(
function_exists
(
$function
))
{
$function
(
$
obj
_type
,
$
object
,
$field
,
$instance
,
$items
);
$function
(
$
entity
_type
,
$
entity
,
$field
,
$instance
,
$items
);
}
$element
[
'#item'
]
=
$items
[
0
];
...
...
@@ -549,7 +549,7 @@ function field_format($obj_type, $object, $field, $item, $formatter_type = NULL,
$items
=
$item
;
$function
=
$field
[
'module'
]
.
'_field_sanitize'
;
if
(
function_exists
(
$function
))
{
$function
(
$
obj
_type
,
$
object
,
$field
,
$instance
,
$items
);
$function
(
$
entity
_type
,
$
entity
,
$field
,
$instance
,
$items
);
}
foreach
(
$items
as
$delta
=>
$item
)
{
...
...
@@ -580,9 +580,9 @@ function field_format($obj_type, $object, $field, $item, $formatter_type = NULL,
* The function takes care of invoking the prepare_view steps. It also respects
* field access permissions.
*
* @param $
obj
_type
* The type of $
object
; e.g. 'node' or 'user'.
* @param $
object
* @param $
entity
_type
* The type of $
entity
; e.g. 'node' or 'user'.
* @param $
entity
* The object containing the field to display. Must at least contain the id
* key and the field data to display.
* @param $field_name
...
...
@@ -616,7 +616,7 @@ function field_format($obj_type, $object, $field, $item, $formatter_type = NULL,
* @return
* A renderable array for the field value.
*/
function
field_view_field
(
$
obj
_type
,
$
object
,
$field_name
,
$display
=
array
(),
$langcode
=
NULL
)
{
function
field_view_field
(
$
entity
_type
,
$
entity
,
$field_name
,
$display
=
array
(),
$langcode
=
NULL
)
{
$output
=
array
();
if
(
$field
=
field_info_field
(
$field_name
))
{
...
...
@@ -627,8 +627,8 @@ function field_view_field($obj_type, $object, $field_name, $display = array(), $
else
{
// When using a view mode, make sure we have settings for it, or fall
// back to the 'full' view mode.
list
(,
,
$bundle
)
=
entity_extract_ids
(
$
obj
_type
,
$
object
);
$instance
=
field_info_instance
(
$
obj
_type
,
$field_name
,
$bundle
);
list
(,
,
$bundle
)
=
entity_extract_ids
(
$
entity
_type
,
$
entity
);
$instance
=
field_info_instance
(
$
entity
_type
,
$field_name
,
$bundle
);
if
(
!
isset
(
$instance
[
'display'
][
$display
]))
{
$display
=
'full'
;
}
...
...
@@ -638,20 +638,20 @@ function field_view_field($obj_type, $object, $field_name, $display = array(), $
// 'single field' mode, to reuse the language fallback logic.
$options
=
array
(
'field_name'
=>
$field_name
,
'language'
=>
field_multilingual_valid_language
(
$langcode
,
FALSE
));
$null
=
NULL
;
list
(
$id
)
=
entity_extract_ids
(
$
obj
_type
,
$
object
);
list
(
$id
)
=
entity_extract_ids
(
$
entity
_type
,
$
entity
);
// First let the field types do their preparation.
_field_invoke_multiple
(
'prepare_view'
,
$
obj
_type
,
array
(
$id
=>
$
object
),
$display
,
$null
,
$options
);
_field_invoke_multiple
(
'prepare_view'
,
$
entity
_type
,
array
(
$id
=>
$
entity
),
$display
,
$null
,
$options
);
// Then let the formatters do their own specific massaging.
_field_invoke_multiple_defaul