You are here

function entity_embed_render_entity in Entity Embed 7.3

Same name and namespace in other branches
  1. 7 includes/entity_embed.display.inc \entity_embed_render_entity()
  2. 7.2 includes/entity_embed.display.inc \entity_embed_render_entity()

Renders an embedded entity.

Parameters

$entity_type: The type of entity, i.e. 'node', 'user'.

$entity: The entity to be rendered.

array $context: (optional) Array of context values, corresponding to the attributes on the embed HTML tag.

Return value

string The HTML of the entity rendered with the Entity Embed Display plugin.

1 call to entity_embed_render_entity()
_entity_embed_render_placeholders in ./entity_embed.module
Implements callback_filter_process().

File

includes/entity_embed.display.inc, line 22
Display functions.

Code

function entity_embed_render_entity($entity_type, $entity, array $context = array()) {

  // Support the deprecated view-mode data attribute.
  if (isset($context['data-view-mode']) && !isset($context['data-entity-embed-display']) && !isset($context['data-entity-embed-settings'])) {
    $context['data-entity-embed-display'] = 'entityreference:entityreference_entity_view';
    $context['data-entity-embed-settings'] = array(
      'view_mode' => $context['data-view-mode'],
    );
  }
  list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);

  // Merge in default attributes.
  $context += array(
    'data-entity-id' => $id,
    'data-entity-type' => $entity_type,
    'data-entity-embed-display' => 'entityreference:entityreference_entity_view',
    'data-entity-embed-settings' => array(),
  );

  // The default Entity Embed Display plugin has been deprecated by the
  // rendered entity field formatter.
  if ($context['data-entity-embed-display'] === 'default') {
    $context['data-entity-embed-display'] = 'entityreference:entityreference_entity_view';
  }

  // Allow modules to alter the entity prior to embed rendering.
  drupal_alter(array(
    "{$context['data-entity-type']}_embed_context",
    'entity_embed_context',
  ), $context, $entity);

  // Build and render the Entity Embed Display plugin, allowing modules to
  // alter the result before rendering.
  $build = render_entity_embed_display_plugin($entity_type, $entity, $context['data-entity-embed-display'], $context['data-entity-embed-settings'], $context);

  // Maintain data-align if it is there.
  if (isset($context['data-align'])) {
    $build['#attributes']['data-align'] = $context['data-align'];
  }
  elseif (isset($context['class'])) {
    $build['#attributes']['class'][] = $context['class'];
  }

  // Maintain data-caption if it is there.
  if (isset($context['data-caption'])) {
    $build['#attributes']['data-caption'] = $context['data-caption'];
  }

  // @todo Should this hook get invoked if $build is an empty array?
  drupal_alter(array(
    "{$context['data-entity-type']}_embed",
    'entity_embed',
  ), $build, $entity, $context);
  $entity_output = drupal_render($build);
  return $entity_output;
}