public function FBLikeboxBlock::build in Facebook Page Plugin 8.2
Same name and namespace in other branches
- 8 src/Plugin/Block/FBLikeboxBlock.php \Drupal\fb_likebox\Plugin\Block\FBLikeboxBlock::build()
Builds and returns the renderable array for this block plugin.
If a block should not be rendered because it has no content, then this method must also ensure to return no content: it must then only return an empty array, or an empty array with #cache set (with cacheability metadata indicating the circumstances for it being empty).
Return value
array A renderable array representing the content of the block.
Overrides BlockPluginInterface::build
See also
\Drupal\block\BlockViewBuilder
File
- src/
Plugin/ Block/ FBLikeboxBlock.php, line 133
Class
- FBLikeboxBlock
- Provides a configurable block with Facebook Likebox's plugin.
Namespace
Drupal\fb_likebox\Plugin\BlockCode
public function build() {
$config = $this
->getConfiguration();
$fb_tabs = [];
if ($config['stream'] == 1) {
$fb_tabs[] = 'timeline';
}
if ($config['events'] == 1) {
$fb_tabs[] = 'events';
}
if ($config['messages'] == 1) {
$fb_tabs[] = 'messages';
}
$render['root-div'] = [
'#type' => 'container',
'#attributes' => [
'id' => [
'fb-root',
],
],
];
$render['block'] = [
'#type' => 'container',
'#attributes' => [
'class' => [
'fb-page',
],
'data-href' => $config['url'],
'data-width' => $config['width'],
'data-height' => $config['height'],
'data-tabs' => implode(',', $fb_tabs),
'data-hide-cover' => $config['hide_header'],
'data-show-facepile' => $config['show_faces'],
'data-hide-cta' => $config['hide_cta'],
'data-small-header' => $config['small_header'],
'data-adapt-container-width' => $config['adapt_container_width'],
],
];
$render['block']['blockquote'] = [
'#type' => 'link',
'#title' => $config['title'],
'#href' => $config['url'],
'#prefix' => '<blockquote cite="' . $config['url'] . '" class = "fb-xfbml-parse-ignore">',
'#suffix' => '</blockquote>',
];
$render['#attached']['library'][] = 'fb_likebox/drupal.fb_likebox';
$render['#attached']['drupalSettings']['fbLikeboxAppId'] = $config['app_id'];
$render['#attached']['drupalSettings']['fbLikeboxLanguage'] = $config['language'];
return $render;
}