public function AddToAnyBlock::build in AddToAny Share Buttons 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/ AddToAnyBlock.php, line 22
Class
- AddToAnyBlock
- Provides an 'AddToAny' block.
Namespace
Drupal\addtoany\Plugin\BlockCode
public function build() {
$build = [];
$node_id = \Drupal::routeMatch()
->getParameter('node');
if (is_numeric($node_id)) {
$node = Node::load($node_id);
}
$is_node = isset($node) && $node instanceof NodeInterface ? true : false;
$data = $is_node ? addtoany_create_entity_data($node) : addtoany_create_data();
$build = [
'#addtoany_html' => $data['addtoany_html'],
'#link_url' => $data['link_url'],
'#link_title' => $data['link_title'],
'#button_setting' => $data['button_setting'],
'#button_image' => $data['button_image'],
'#universal_button_placement' => $data['universal_button_placement'],
'#buttons_size' => $data['buttons_size'],
'#theme' => 'addtoany_standard',
'#cache' => [
'contexts' => [
'url',
],
],
];
if ($is_node) {
$build['#addtoany_html'] = \Drupal::token()
->replace($data['addtoany_html'], [
'node' => $node,
]);
}
return $build;
}