AddToAnyBlock.php in AddToAny Share Buttons 8
File
src/Plugin/Block/AddToAnyBlock.php
View source
<?php
namespace Drupal\addtoany\Plugin\Block;
use Drupal\Core\Block\BlockBase;
use Drupal\node\Entity\Node;
use Drupal\node\NodeInterface;
class AddToAnyBlock extends BlockBase {
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;
}
}