summaryrefslogtreecommitdiff
path: root/modules/field
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2010-01-02 15:00:34 +0000
committerDries Buytaert <dries@buytaert.net>2010-01-02 15:00:34 +0000
commitb12d812b9397609a5853d8c2b73f29d282496fd9 (patch)
treecf6de6724ccba65a56aa3d73f6bf554ccc3c0313 /modules/field
parent89028a43bbbaf73e6aa1e8e00bc12d46d1fc7119 (diff)
downloadbrdo-b12d812b9397609a5853d8c2b73f29d282496fd9.tar.gz
brdo-b12d812b9397609a5853d8c2b73f29d282496fd9.tar.bz2
- Patch #665878 by yched: fixed field_extra_fields()
Diffstat (limited to 'modules/field')
-rw-r--r--modules/field/field.api.php6
-rw-r--r--modules/field/field.attach.inc22
-rw-r--r--modules/field/field.module60
3 files changed, 42 insertions, 46 deletions
diff --git a/modules/field/field.api.php b/modules/field/field.api.php
index 52000d922..b54dd63f4 100644
--- a/modules/field/field.api.php
+++ b/modules/field/field.api.php
@@ -19,9 +19,7 @@
* field_attach_extra_weight() to retrieve the user-defined weight when
* inserting the component.
*
- * @param $bundle
- * The name of the bundle being considered.
- * @return
+ * @return @todo
* An array of 'pseudo-field' components. The keys are the name of the element
* as it appears in the form structure. The values are arrays with the
* following key/value pairs:
@@ -31,7 +29,7 @@
* - view: (optional) The name of the element as it appears in the rendered
* structure, if different from the name in the form.
*/
-function hook_field_extra_fields($bundle) {
+function hook_field_extra_fields() {
$extra = array();
if ($type = node_type_get_type($bundle)) {
diff --git a/modules/field/field.attach.inc b/modules/field/field.attach.inc
index 373e8c51d..ea58b0282 100644
--- a/modules/field/field.attach.inc
+++ b/modules/field/field.attach.inc
@@ -491,7 +491,7 @@ function field_attach_form($obj_type, $object, &$form, &$form_state, $langcode =
list($id, $vid, $bundle) = entity_extract_ids($obj_type, $object);
$form['#attached']['css'][] = drupal_get_path('module', 'field') . '/theme/field.css';
$form['#pre_render'][] = '_field_extra_weights_pre_render';
- $form['#extra_fields'] = field_extra_fields($bundle);
+ $form['#extra_fields'] = field_extra_fields($obj_type, $bundle);
// Let other modules make changes to the form.
// Avoid module_invoke_all() to let parameters be taken by reference.
@@ -1200,7 +1200,7 @@ function field_attach_view($obj_type, $object, $view_mode = 'full', $langcode =
// Add custom weight handling.
list($id, $vid, $bundle) = entity_extract_ids($obj_type, $object);
$output['#pre_render'][] = '_field_extra_weights_pre_render';
- $output['#extra_fields'] = field_extra_fields($bundle);
+ $output['#extra_fields'] = field_extra_fields($obj_type, $bundle);
// Include CSS styles.
$output['#attached']['css'][] = drupal_get_path('module', 'field') . '/theme/field.css';
@@ -1261,24 +1261,6 @@ function field_attach_preprocess($obj_type, $object, $element, &$variables) {
}
/**
- * Retrieve the user-defined weight for a 'pseudo-field' component.
- *
- * @param $bundle
- * The bundle name.
- * @param $pseudo_field
- * The name of the 'pseudo-field'.
- * @return
- * The weight for the 'pseudo-field', respecting the user settings stored by
- * field.module.
- */
-function field_attach_extra_weight($bundle, $pseudo_field) {
- $extra = field_extra_fields($bundle);
- if (isset($extra[$pseudo_field])) {
- return $extra[$pseudo_field]['weight'];
- }
-}
-
-/**
* Implements hook_node_prepare_translation().
*
* TODO D7: We do not yet know if this really belongs in Field API.
diff --git a/modules/field/field.module b/modules/field/field.module
index 0f44c99b0..62dbc68e7 100644
--- a/modules/field/field.module
+++ b/modules/field/field.module
@@ -370,38 +370,54 @@ function _field_sort_items_value_helper($a, $b) {
/**
* Registry of pseudo-field components in a given bundle.
*
- * @param $bundle_name
+ * @param $obj_type
+ * The type of $object; e.g. 'node' or 'user'.
+ * @param $bundle
* The bundle name.
* @return
* The array of pseudo-field elements in the bundle.
*/
-function field_extra_fields($bundle_name) {
+function field_extra_fields($obj_type, $bundle) {
$info = &drupal_static(__FUNCTION__, array());
if (empty($info)) {
- $info = array();
- $bundles = field_info_bundles();
- foreach ($bundles as $bundle => $bundle_info) {
- // Gather information about non-field object additions.
- $extra = module_invoke_all('field_extra_fields', $bundle);
- drupal_alter('field_extra_fields', $extra, $bundle);
-
- // Add saved weights.
- foreach (variable_get("field_extra_weights_$bundle", array()) as $key => $value) {
- // Some stored entries might not exist anymore, for instance if uploads
- // have been disabled or vocabularies were deleted.
- if (isset($extra[$key])) {
- $extra[$key]['weight'] = $value;
+ $info = (array) module_invoke_all('field_extra_fields');
+ drupal_alter('field_extra_fields', $info);
+
+ // 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 ($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;
+ }
}
}
- $info[$bundle] = $extra;
}
}
- if (array_key_exists($bundle_name, $info)) {
- return $info[$bundle_name];
- }
- else {
- return array();
+
+ return isset($info[$obj_type][$bundle]) ? $info[$obj_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 $bundle
+ * The bundle name.
+ * @param $pseudo_field
+ * The name of the 'pseudo-field'.
+ * @return
+ * 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);
+ if (isset($extra[$pseudo_field])) {
+ return $extra[$pseudo_field]['weight'];
}
}
@@ -425,7 +441,7 @@ function _field_extra_weights_pre_render($elements) {
}
/**
- * Clear the field info and field date caches.
+ * Clear the field info and field data caches.
*/
function field_cache_clear() {
cache_clear_all('*', 'cache_field', TRUE);