Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
drupal
Commits
814f4c8e
Commit
814f4c8e
authored
Dec 26, 2009
by
Dries
Browse files
- Patch
#667040
by effulgentsia: optimize template_preprocess_field().
parent
95a0f85a
Changes
4
Hide whitespace changes
Inline
Side-by-side
modules/field/field.default.inc
View file @
814f4c8e
...
...
@@ -203,6 +203,7 @@ function field_default_view($obj_type, $object, $field, $instance, $langcode, $i
'#language'
=>
$langcode
,
'#field_name'
=>
$field
[
'field_name'
],
'#field_type'
=>
$field
[
'type'
],
'#field_translatable'
=>
$field
[
'translatable'
],
'#object_type'
=>
$obj_type
,
'#bundle'
=>
$bundle
,
'#object'
=>
$object
,
...
...
modules/field/field.module
View file @
814f4c8e
...
...
@@ -742,13 +742,11 @@ function field_extract_bundle($obj_type, $bundle) {
*/
function
template_preprocess_field
(
&
$variables
)
{
$element
=
$variables
[
'element'
];
$instance
=
field_info_instance
(
$element
[
'#object_type'
],
$element
[
'#field_name'
],
$element
[
'#bundle'
]);
$field
=
field_info_field
(
$element
[
'#field_name'
]);
// @todo Convert to using drupal_html_class() after benchmarking the impact of
// doing so.
$field_type_css
=
strtr
(
$field
[
'
type'
],
'_'
,
'-'
);
$field_name_css
=
strtr
(
$
field
[
'field_name'
],
'_'
,
'-'
);
$field_type_css
=
strtr
(
$
element
[
'#
field
_
type'
],
'_'
,
'-'
);
$field_name_css
=
strtr
(
$
element
[
'
#
field_name'
],
'_'
,
'-'
);
// Prepare an $items variable that the template can simply loop on.
// Filter out non-children properties that might have been added if the
...
...
@@ -757,20 +755,19 @@ function template_preprocess_field(&$variables) {
$additions
=
array
(
'object'
=>
$element
[
'#object'
],
'field'
=>
$field
,
'instance'
=>
$instance
,
'build_mode'
=>
$element
[
'#build_mode'
],
'items'
=>
$items
,
'field_type'
=>
$field
[
'
type'
],
'field_name'
=>
$
field
[
'field_name'
],
'field_type'
=>
$
element
[
'#
field
_
type'
],
'field_name'
=>
$
element
[
'
#
field_name'
],
'field_type_css'
=>
$field_type_css
,
'field_name_css'
=>
$field_name_css
,
'label'
=>
check_plain
(
$element
[
'#title'
]),
'label_display'
=>
$element
[
'#label_display'
],
'label_hidden'
=>
$element
[
'#label_display'
]
==
'hidden'
,
'field_language'
=>
$element
[
'#language'
],
'field_translatable'
=>
$field
[
'
translatable'
],
'field_translatable'
=>
$
element
[
'#
field
_
translatable'
],
'classes_array'
=>
array
(
'field'
,
'field-name-'
.
$field_name_css
,
'field-type-'
.
$field_type_css
,
'field-label-'
.
$element
[
'#label_display'
],
...
...
@@ -785,6 +782,7 @@ function template_preprocess_field(&$variables) {
$variables
=
array_merge
(
$variables
,
$additions
);
// Initialize attributes for each item.
$variables
[
'item_attributes_array'
]
=
array
();
foreach
(
$variables
[
'items'
]
as
$delta
=>
$item
)
{
$variables
[
'item_attributes_array'
][
$delta
]
=
array
();
}
...
...
modules/field/theme/field.tpl.php
View file @
814f4c8e
...
...
@@ -13,6 +13,7 @@
* CSS. It can be manipulated through the variable $classes_array from
* preprocess functions. The default values can be one or more of the
* following:
* - field: The current template type, i.e., "theming hook".
* - field-name-[field_name]: The current field name. For example, if the
* field name is "field_description" it would result in
* "field-name-field-description".
...
...
@@ -23,7 +24,6 @@
*
* Other variables:
* - $object: The object to which the field is attached.
* - $field: The field array.
* - $build_mode: Build mode, e.g. 'full', 'teaser'...
* - $field_name: The field name.
* - $field_type: The field type.
...
...
@@ -38,7 +38,7 @@
* @see template_preprocess_field()
*/
?>
<div
class=
"
field
<?php
print
$classes
;
?>
clearfix"
<?php
print
$attributes
;
?>
>
<div
class=
"
<?php
print
$classes
;
?>
clearfix"
<?php
print
$attributes
;
?>
>
<?php
if
(
!
$label_hidden
)
:
?>
<div
class=
"field-label"
<?php
print
$title_attributes
;
?>
>
<?php
print
$label
?>
:
</div>
<?php
endif
;
?>
...
...
modules/rdf/rdf.module
View file @
814f4c8e
...
...
@@ -446,14 +446,12 @@ function rdf_preprocess_node(&$variables) {
* Implements MODULE_preprocess_HOOK().
*/
function
rdf_preprocess_field
(
&
$variables
)
{
$entity_type
=
$variables
[
'element'
][
'#object_type'
];
$instance
=
$variables
[
'instance'
];
$mapping
=
rdf_mapping_load
(
$entity_type
,
$instance
[
'bundle'
]);
$field_name
=
$instance
[
'field_name'
];
$items
=
$variables
[
'element'
][
'#items'
];
$element
=
$variables
[
'element'
];
$mapping
=
rdf_mapping_load
(
$element
[
'#object_type'
],
$element
[
'#bundle'
]);
$field_name
=
$element
[
'#field_name'
];
if
(
!
empty
(
$mapping
)
&&
!
empty
(
$mapping
[
$field_name
]))
{
foreach
(
$items
as
$delta
=>
$item
)
{
foreach
(
$
element
[
'#
items
'
]
as
$delta
=>
$item
)
{
$variables
[
'item_attributes_array'
][
$delta
]
=
rdf_rdfa_attributes
(
$mapping
[
$field_name
],
$item
);
}
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a 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