public function FacebookAlbumBlock::build in Facebook Album 8
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/ FacebookAlbumBlock.php, line 152 - Contains \Drupal\facebook_album\Plugin\Block\FacebookAlbumBlock.
Class
- FacebookAlbumBlock
- Defines a facebook album block block type.
Namespace
Drupal\facebook_album\Plugin\BlockCode
public function build() {
// Due to not having access to any entity info, we're storing settings via a hash
// @TODO: Find a better way for this
$config = $this
->getConfiguration();
$hash = hash_hmac('md5', serialize($config), 'facebook_album');
// Output the wrappers
$content = [];
$content['#attributes']['class'] = [
'block',
'block-facebook-album',
];
$content[] = [
'#theme_wrappers' => [
'container' => [
'#attributes' => [
'id' => 'fba-' . $hash,
'class' => [
'facebook-album-container',
],
],
],
],
'header' => [
'#markup' => '<div class="fb-album-header"></div>',
],
'albums' => [
'#markup' => '<div class="facebook-album-images-container"></div>',
],
'loading' => [
'#markup' => '<div class="fb-loading-icon"></div>',
],
];
// Add the library and settings
$content['#attached'] = [
'library' => [
'facebook_album/facebook_album',
],
'drupalSettings' => [
'facebook_album' => [
'fba-' . $hash => $config,
],
],
];
return $content;
}