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
a0f3abf0
Commit
a0f3abf0
authored
Dec 31, 2009
by
Dries
Browse files
- Patch
#661494
by yched: fixed direct calls to node_view() do not trigger f_a_prepare_view().
parent
87cbbe65
Changes
4
Hide whitespace changes
Inline
Side-by-side
modules/field/field.attach.inc
View file @
a0f3abf0
...
...
@@ -1111,15 +1111,41 @@ function field_attach_query_revisions($field_id, $conditions, $options = array()
}
/**
* Allow formatters to act on fieldable objects prior to rendering.
* Prepare field data prior to display.
*
* This function must be called before field_attach_view(). It lets field
* types and formatters load additional data needed for display, and
* therefore accepts an array of objects to allow query optimisation when
* displaying lists of objects.
*
* @param $obj_type
* The type of $objects; e.g. 'node' or 'user'.
* @param $objects
* An array of objects, keyed by object id.
* @param $view_mode
* View mode, e.g. 'full', 'teaser'...
*/
function
field_attach_prepare_view
(
$obj_type
,
$objects
,
$view_mode
=
'full'
)
{
// To ensure hooks are only run once per entity, only process items without
// the _field_view_prepared flag.
// @todo: resolve this more generally for both entity and field level hooks.
$prepare
=
array
();
foreach
(
$objects
as
$id
=>
$object
)
{
if
(
empty
(
$object
->
_field_view_prepared
))
{
// Add this entity to the items to be prepared.
$prepare
[
$id
]
=
$object
;
// Mark this item as prepared.
$object
->
_field_view_prepared
=
TRUE
;
}
}
// First let the field types do their preparation.
_field_invoke_multiple
(
'prepare_view'
,
$obj_type
,
$
objects
);
_field_invoke_multiple
(
'prepare_view'
,
$obj_type
,
$
prepare
);
// Then let the formatters do their own specific massaging.
// field_default_prepare_view() takes care of dispatching to the correct
// formatters according to the display settings for the view mode.
_field_invoke_multiple_default
(
'prepare_view'
,
$obj_type
,
$
objects
,
$view_mode
);
_field_invoke_multiple_default
(
'prepare_view'
,
$obj_type
,
$
prepare
,
$view_mode
);
}
/**
...
...
@@ -1128,6 +1154,9 @@ function field_attach_prepare_view($obj_type, $objects, $view_mode = 'full') {
* Each field is displayed according to the display options specified in the
* $instance definition for the given $view_mode.
*
* The object must have run through field_attach_prepare_view() beforehands.
* @see field_attach_prepare_view()
*
* Sample structure:
* @code
* array(
...
...
@@ -1185,6 +1214,11 @@ function field_attach_view($obj_type, $object, $view_mode = 'full', $langcode =
);
drupal_alter
(
'field_attach_view'
,
$output
,
$context
);
// Reset the _field_view_prepared flag set in field_attach_prepare_view(),
// in case the same object is displayed with different settings later in
// the request.
unset
(
$object
->
_field_view_prepared
);
return
$output
;
}
...
...
modules/node/node.module
View file @
a0f3abf0
...
...
@@ -1236,9 +1236,10 @@ function node_build_content($node, $view_mode = 'full') {
}
// Build fields content.
// @todo field_attach_prepare_view() is only invoked by node_view_multiple(),
// all other entities invoke it _here_.
//field_attach_prepare_view('node', array($node->nid => $node), $view_mode);
// In case of a multiple view, node_view_multiple() already ran the
// 'prepare_view' step. An internal flag prevents the operation from running
// twice.
field_attach_prepare_view
(
'node'
,
array
(
$node
->
nid
=>
$node
),
$view_mode
);
$node
->
content
+=
field_attach_view
(
'node'
,
$node
,
$view_mode
);
// Always display a read more link on teasers because we have no way
...
...
modules/rdf/rdf.module
View file @
a0f3abf0
...
...
@@ -582,12 +582,6 @@ function rdf_field_attach_view_alter(&$output, $context) {
$element
=
&
$output
[
$field_name
];
if
(
$element
[
'#field_type'
]
==
'taxonomy_term'
&&
$element
[
'#formatter'
]
==
'taxonomy_term_link'
)
{
foreach
(
$element
[
'#items'
]
as
$delta
=>
$item
)
{
// @todo Remove this when "node_view() does not call
// field_attach_prepare_view()" bug is fixed.
// See http://drupal.org/node/493314.
if
(
!
isset
(
$item
[
'taxonomy_term'
]))
{
$item
[
'taxonomy_term'
]
=
taxonomy_term_load
(
$item
[
'tid'
]);
}
$term
=
$item
[
'taxonomy_term'
];
if
(
!
empty
(
$term
->
rdf_mapping
[
'rdftype'
]))
{
$element
[
$delta
][
'#options'
][
'attributes'
][
'typeof'
]
=
$term
->
rdf_mapping
[
'rdftype'
];
...
...
modules/taxonomy/taxonomy.module
View file @
a0f3abf0
...
...
@@ -1079,12 +1079,6 @@ function taxonomy_field_formatter_view($object_type, $object, $field, $instance,
switch
(
$display
[
'type'
])
{
case
'taxonomy_term_link'
:
foreach
(
$items
as
$delta
=>
$item
)
{
// @todo Remove this when "node_view() does not call
// field_attach_prepare_view()" bug is fixed.
// See http://drupal.org/node/493314.
if
(
!
isset
(
$item
[
'taxonomy_term'
]))
{
$item
[
'taxonomy_term'
]
=
taxonomy_term_load
(
$item
[
'tid'
]);
}
$term
=
$item
[
'taxonomy_term'
];
$element
[
$delta
]
=
array
(
'#type'
=>
'link'
,
...
...
Write
Preview
Markdown
is supported
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