You are here

function hook_entity_diff in Diff 7.3

Allow modules to provide a comparison about entity properties.

Parameters

object $old_entity: The older entity revision.

object $new_entity: The newer entity revision.

array $context: An associative array containing:

  • entity_type: The entity type; e.g., 'node' or 'user'.
  • old_entity: The older entity.
  • new_entity: The newer entity.
  • view_mode: The view mode to use. Defaults to FALSE. If no view mode is given, the recommended fallback view mode is 'default'.
  • states: An array of view states. These could be one of:
    • raw: The raw value of the diff, the classic 7.x-2.x view.
    • rendered: The rendered HTML as determined by the view mode. Only return markup for this state if the value is normally shown by this view mode. The user will most likely be able to see the raw or raw_plain state, so this is optional.

The rendering state is a work in progress.

Conditionally, you can get these states, but setting these will override the user selectable markdown method.

  • raw_plain: As raw, but text should be markdowned.
  • rendered_plain: As rendered, but text should be markdowned.

Return value

array An associative array of values keyed by the entity property.

This is effectively an unnested Form API-like structure.

States are returned as follows:

$results['line'] = array( '#name' => t('Line'), '#states' => array( 'raw' => array( '#old' => '<p class="line">This was the old line number [tag].</p>', '#new' => '<p class="line">This is the new line [tag].</p>', ), 'rendered' => array( '#old' => '<p class="line">This was the old line number <span class="line-number">57</span>.</p>', '#new' => '<p class="line">This is the new line <span class="line-number">57</span>.</p>', ), ), );

For backwards compatibility, no changes are required to support states, but it is recommended to provide a better UI for end users.

For example, the following example is equivalent to returning the raw state from the example above.

$results['line'] = array( '#name' => t('Line'), '#old' => '<p class="line">This was the old line number [tag].</p>', '#new' => '<p class="line">This is the new line [tag].</p>', );

3 functions implement hook_entity_diff()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

diff_entity_diff in ./diff.diff.inc
Implements hook_entity_diff().
node_entity_diff in ./diff.module
Implements hook_entity_diff() on behalf of the Node module.
user_entity_diff in ./diff.module
Implements hook_entity_diff() on behalf of the User module.
1 invocation of hook_entity_diff()
diff_compare_entities in ./diff.pages.inc
Generic callback to compare two entities.

File

./diff.api.php, line 77
Hooks provided by the diff module.

Code

function hook_entity_diff($old_entity, $new_entity, $context) {
  $results = array();
  if ($context['entity_type'] == 'node') {
    $type = node_type_get_type($new_entity);
    $results['title'] = array(
      '#name' => $type->title_label,
      '#old' => array(
        $old_entity->title,
      ),
      '#new' => array(
        $new_entity->title,
      ),
      '#weight' => -5,
      '#settings' => array(
        'show_header' => FALSE,
      ),
    );
  }
  return $results;
}