public static function DrupalInstantArticleDisplay::create in Facebook Instant Articles 7
Parameters
\stdClass $node:
Return value
\Drupal\fb_instant_articles_display\DrupalInstantArticleDisplay
2 calls to DrupalInstantArticleDisplay::create()
- fb_instant_articles_api_rules_import_article in modules/
fb_instant_articles_api_rules/ fb_instant_articles_api_rules.module - Implementation of a Facebook instant article import.
- fb_instant_articles_display_node_load in modules/
fb_instant_articles_display/ fb_instant_articles_display.module - Implements hook_node_load().
File
- modules/
fb_instant_articles_display/ src/ DrupalInstantArticleDisplay.php, line 81 - Contains \Drupal\fb_instant_articles_display\DrupalInstantArticleDisplay.
Class
- DrupalInstantArticleDisplay
- Facebook Instant Article node wrapper class. Builds up an InstantArticle object using field formatters.
Namespace
Drupal\fb_instant_articles_displayCode
public static function create($node, $layoutSettings) {
// InstantArticle object for the node. This will be built up by any field
// formatters and rendered out in hook_preprocess_node().
$instantArticle = InstantArticle::create()
->addMetaProperty('op:generator:application', 'drupal/fb_instant_articles')
->addMetaProperty('op:generator:application:version', self::FB_INSTANT_ARTICLES_VERSION)
->withCanonicalUrl(url('node/' . $node->nid, array(
'absolute' => TRUE,
)))
->withStyle(variable_get('fb_instant_articles_style', 'default'));
// InstantArticles header, at this point, only have publish an modify
// times to add.
$header = Header::create()
->withTitle($node->title)
->withPublishTime(Time::create(Time::PUBLISHED)
->withDatetime(\DateTime::createFromFormat('U', $node->created)))
->withModifyTime(Time::create(Time::MODIFIED)
->withDatetime(\DateTime::createFromFormat('U', $node->changed)));
// Default the article author to the username.
$author = user_load($node->uid);
if ($author) {
$header
->addAuthor(Author::create()
->withName($author->name));
}
$instantArticle
->withHeader($header);
$display = new DrupalInstantArticleDisplay($node, $layoutSettings, $instantArticle);
$display
->addAnalyticsFromSettings();
$display
->addAdsFromSettings();
return $display;
}