field_attach_load_revision

7 field.attach.inc field_attach_load_revision($entity_type, $entities, $options = array())
8 field.attach.inc field_attach_load_revision($entity_type, $entities, $options = array())

Load all fields for previous versions of a group of entities.

Loading different versions of the same entities is not supported, and should be done by separate calls to the function.

field_attach_load_revision() is automatically called by the default entity controller class, and thus, in most cases, doesn't need to be explicitly called by the entity type module.

Parameters

$entity_type: The type of $entity; e.g. 'node' or 'user'.

$entities: An array of entities for which to load fields, keyed by entity ID. Each entity needs to have its 'bundle', 'id' and (if applicable) 'revision' keys filled. The function adds the loaded field data directly in the entity objects of the $entities array.

$options: An associative array of additional options. See field_attach_load() for details.

Related topics

5 calls to field_attach_load_revision()

File

modules/field/field.attach.inc, line 752
Field attach API, allowing entities (nodes, users, ...) to be 'fieldable'.

Code

function field_attach_load_revision($entity_type, $entities, $options = array()) {
  return field_attach_load($entity_type, $entities, FIELD_LOAD_REVISION, $options);
}

Comments

Also loads the current revision...

The current revision will still be stored as the first index under the language array. So in order to truly get the revision you're looking for you need to shift the first element off of that array (after loading up all your field instances, ugh). It also doesn't make any sense because in other places the array under language refers to multi-value fields and not revisions.

Basic example:

<?php
  $entities
[$id]->$my_revision_key = $my_revision;
 
field_attach_load_revision('my_entity', $entities); 
 
$my_entity = $entities[$id];

 
$instances = field_load_instances('my_entity', 'my_bundle');

  foreach (
$instances as $name => $instance) {
   
// This is dumb that you need to do this.
   
if (isset($my_entity->{$name}['und'])) {
     
array_shift($my_entity->{$name}['und']);
    }
  }
 
$render_array = field_attach_view('my_entity', $my_entity);
?>

Login or register to post comments