You are here

function hook_fb_instant_articles_article_alter in Facebook Instant Articles 7.2

Alter the InstantArticle object before retrieving from the ArticleWrapper.

The InstantArticle object is provided by the FB Instant SDK. See their documentation for details on how to work with the SDK to customize your Instant Articles.

Parameters

\Facebook\InstantArticles\Elements\InstantArticle $instantArticle: The SDK InstantArticle object before it is retrieved from ArticleWrapper.

array $context: An associative array of all contextual information for use in altering the InstantArticle object. When interacting with ArticleWrapper directly, modules may set additional context with ArticleWrapper::setContext().

See also

\Drupal\fb_instant_articles\ArticleWrapper::create()

\Drupal\fb_instant_articles\ArticleWrapper::__construct()

1 function implements hook_fb_instant_articles_article_alter()

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

fb_instant_articles_display_fb_instant_articles_article_alter in modules/fb_instant_articles_display/fb_instant_articles_display.module
Implements hook_fb_instant_articles_article_alter().
1 invocation of hook_fb_instant_articles_article_alter()
ArticleWrapper::__construct in src/ArticleWrapper.php
ArticleWrapper constructor.

File

./fb_instant_articles.api.php, line 30
Hooks provided by Facebook Instant Articles Base module.

Code

function hook_fb_instant_articles_article_alter($instantArticle, $context) {

  // Check to see if a module like fb_instant_articles_display has set Entity
  // context.
  if (isset($context['entity_type']) && isset($context['entity'])) {

    // Example: Set the author using a custom callback.
    $byline = custom_fb_instant_articles_byline_callback($context['entity_type'], $context['entity']);
    $instantArticle
      ->getHeader()
      ->addAuthor(\Facebook\InstantArticles\Elements\Author::create()
      ->withName($byline));
  }
}