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
b12d812b
Commit
b12d812b
authored
Jan 02, 2010
by
Dries Buytaert
Browse files
- Patch
#665878
by yched: fixed field_extra_fields()
parent
89028a43
Changes
7
Hide whitespace changes
Inline
Side-by-side
modules/field/field.api.php
View file @
b12d812b
...
...
@@ -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
))
{
...
...
modules/field/field.attach.inc
View file @
b12d812b
...
...
@@ -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'
;
...
...
@@ -1260,24 +1260,6 @@ function field_attach_preprocess($obj_type, $object, $element, &$variables) {
drupal_alter
(
'field_attach_preprocess'
,
$variables
,
$context
);
}
/**
* 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().
*
...
...
modules/field/field.module
View file @
b12d812b
...
...
@@ -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
(
$bundl
e_nam
e
)
{
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 dat
e
caches.
* Clear the field info and field dat
a
caches.
*/
function
field_cache_clear
()
{
cache_clear_all
(
'*'
,
'cache_field'
,
TRUE
);
...
...
modules/field_ui/field_ui.admin.inc
View file @
b12d812b
...
...
@@ -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
();
...
...
modules/field_ui/field_ui.module
View file @
b12d812b
...
...
@@ -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
);
}
}
/**
...
...
modules/poll/poll.module
View file @
b12d812b
...
...
@@ -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
;
}
...
...
modules/user/user.module
View file @
b12d812b
...
...
@@ -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
)
{
...
...
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