public static function AmpSocialPost::preRenderSocialPost in Accelerated Mobile Pages (AMP) 8.3
Pre-render callback.
Processes the post and attaches libraries.
1 call to AmpSocialPost::preRenderSocialPost()
- AmpSocialPostTest::testpreRenderSocialPost in tests/
src/ Unit/ AmpSocialPostTest.php - @covers ::preRenderSocialPost @dataProvider renderData
File
- src/
Element/ AmpSocialPost.php, line 65
Class
- AmpSocialPost
- Provides AMP social post elements.
Namespace
Drupal\amp\ElementCode
public static function preRenderSocialPost($element) {
$url = $element['#url'];
// If provider is invalid, the element is empty.
if (!($provider = static::getProvider($url))) {
return [];
}
else {
$element['#provider'] = $provider;
}
// Set the url or id.
switch ($provider) {
case 'twitter':
$element['#attributes']['data-tweetid'] = static::getId($url, $provider);
break;
case 'instagram':
$element['#attributes']['data-shortcode'] = static::getId($url, $provider);
break;
case 'pinterest':
$element['#attributes']['data-href'] = $url;
$element['#attributes']['data-do'] = 'embedPin';
break;
default:
$element['#attributes']['data-href'] = $url;
break;
}
// Get rid of empty attributes.
$element['#attributes'] = array_filter($element['#attributes']);
// Attach the right library.
$libraries = static::getLibraries();
$element['#attached']['library'][] = $libraries[$provider];
return $element;
}