You are here

function fb_instant_articles_display_entity_load in Facebook Instant Articles 7.2

Implements hook_entity_load().

File

modules/fb_instant_articles_display/fb_instant_articles_display.module, line 16
Hook implementations for Facebook Instant Articles Display module.

Code

function fb_instant_articles_display_entity_load($entities, $type) {
  $enabled_entity_types = fb_instant_articles_display_get_article_entity_types();
  foreach ($entities as $entity) {

    // Only proceed if the entity is of the configured entity type and bundle.
    list($id, $vid, $bundle) = entity_extract_ids($type, $entity);
    if (!in_array($type, array_keys($enabled_entity_types)) || !in_array($bundle, array_keys($enabled_entity_types[$type]))) {
      return FALSE;
    }

    // We add Entity-specific information when constructing the ArticleWrapper
    // object, so that other modules can make use of this when implementing
    // hook_fb_instant_articles_article_alter(). We then attach the
    // InstantArticle object directly onto the Entity so that it will be
    // available during hook_field_formatter_view() for mapping field data onto
    // the InstantArticle object.
    $context = array(
      'entity_type' => $type,
      'entity' => $entity,
    );
    $entity->fb_instant_article = \Drupal\fb_instant_articles\ArticleWrapper::create($context)
      ->getArticle();
  }
}