summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/field/field.api.php6
-rw-r--r--modules/field/field.attach.inc22
-rw-r--r--modules/field/field.module60
-rw-r--r--modules/field_ui/field_ui.admin.inc11
-rw-r--r--modules/field_ui/field_ui.module22
-rw-r--r--modules/poll/poll.module16
-rw-r--r--modules/user/user.module22
7 files changed, 78 insertions, 81 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);
diff --git a/modules/field_ui/field_ui.admin.inc b/modules/field_ui/field_ui.admin.inc
index 9143e99f4..c809adc4c 100644
--- a/modules/field_ui/field_ui.admin.inc
+++ b/modules/field_ui/field_ui.admin.inc
@@ -83,7 +83,7 @@ function field_ui_field_overview_form($form, &$form_state, $obj_type, $bundle) {
$field_types = field_info_field_types();
$widget_types = field_info_widget_types();
- $extra = field_extra_fields($bundle);
+ $extra = field_extra_fields($obj_type, $bundle);
// Store each default weight so that we can add the 'add new' rows after them.
$weights = array();
@@ -479,12 +479,9 @@ function field_ui_field_overview_form_submit($form, &$form_state) {
}
}
- if ($extra) {
- variable_set("field_extra_weights_$bundle", $extra);
- }
- else {
- variable_del("field_extra_weights_$bundle");
- }
+ $extra_weights = variable_get('field_extra_weights', array());
+ $extra_weights[$obj_type][$bundle] = $extra;
+ variable_set('field_extra_weights', $extra_weights);
$destinations = array();
diff --git a/modules/field_ui/field_ui.module b/modules/field_ui/field_ui.module
index b24ef7776..155849bce 100644
--- a/modules/field_ui/field_ui.module
+++ b/modules/field_ui/field_ui.module
@@ -248,7 +248,7 @@ function field_ui_field_ui_view_modes_tabs() {
/**
* Implements hook_field_attach_create_bundle().
*/
-function field_ui_field_attach_create_bundle($bundle) {
+function field_ui_field_attach_create_bundle($obj_type, $bundle) {
// When a new bundle is created, the menu needs to be rebuilt to add our
// menu item tabs.
variable_set('menu_rebuild_needed', TRUE);
@@ -257,18 +257,26 @@ function field_ui_field_attach_create_bundle($bundle) {
/**
* Implements hook_field_attach_rename_bundle().
*/
-function field_ui_field_attach_rename_bundle($bundle_old, $bundle_new) {
- if ($bundle_old !== $bundle_new && $extra = variable_get("field_extra_weights_$bundle_old", array())) {
- variable_set("field_extra_weights_$bundle_new", $extra);
- variable_del("field_extra_weights_$bundle_old");
+function field_ui_field_attach_rename_bundle($obj_type, $bundle_old, $bundle_new) {
+ if ($bundle_old !== $bundle_new) {
+ $extra_weights = variable_get('field_extra_weights', array());
+ if (isset($info[$obj_type][$bundle_old])) {
+ $extra_weights[$obj_type][$bundle_new] = $extra_weights[$obj_type][$bundle_old];
+ unset($extra_weights[$obj_type][$bundle_old]);
+ variable_set('field_extra_weights', $extra_weights);
+ }
}
}
/**
* Implements hook_field_attach_delete_bundle().
*/
-function field_ui_field_attach_delete_bundle($bundle) {
- variable_del('field_extra_weights_' . $bundle);
+function field_ui_field_attach_delete_bundle($obj_type, $bundle) {
+ $extra_weights = variable_get('field_extra_weights', array());
+ if (isset($extra_weights[$obj_type][$bundle])) {
+ unset($extra_weights[$obj_type][$bundle]);
+ variable_set('field_extra_weights', $extra_weights);
+ }
}
/**
diff --git a/modules/poll/poll.module b/modules/poll/poll.module
index 45df576a3..9c48de6b6 100644
--- a/modules/poll/poll.module
+++ b/modules/poll/poll.module
@@ -193,21 +193,19 @@ function poll_node_info() {
/**
* Implements hook_field_extra_fields().
*/
-function poll_field_extra_fields($bundle) {
- $extra = array();
-
- if ($bundle == 'poll') {
- $extra['choice_wrapper'] = array(
+function poll_field_extra_fields() {
+ $extra['node']['poll'] = array(
+ 'choice_wrapper' => array(
'label' => t('Poll choices'),
'description' => t('Poll module choices.'),
'weight' => -4,
- );
- $extra['settings'] = array(
+ ),
+ 'settings' => array(
'label' => t('Poll settings'),
'description' => t('Poll module settings.'),
'weight' => -3,
- );
- }
+ ),
+ );
return $extra;
}
diff --git a/modules/user/user.module b/modules/user/user.module
index 9767c3288..1593468d2 100644
--- a/modules/user/user.module
+++ b/modules/user/user.module
@@ -155,28 +155,26 @@ function user_entity_info() {
/**
* Implements hook_field_extra_fields().
*/
-function user_field_extra_fields($bundle) {
- $extra = array();
-
- if ($bundle == 'user') {
- $extra['account'] = array(
+function user_field_extra_fields() {
+ $return['user']['user'] = array(
+ 'account' => array(
'label' => 'User name and password',
'description' => t('User module account form elements'),
'weight' => -10,
- );
- $extra['timezone'] = array(
+ ),
+ 'timezone' => array(
'label' => 'Timezone',
'description' => t('User module timezone form element.'),
'weight' => 6,
- );
- $extra['summary'] = array(
+ ),
+ 'summary' => array(
'label' => 'History',
'description' => t('User module history view element.'),
'weight' => 5,
- );
- }
+ ),
+ );
- return $extra;
+ return $return;
}
function user_external_load($authname) {