public function SocialSimpleBlock::build in Social simple 8
Same name and namespace in other branches
- 2.0.x src/Plugin/Block/SocialSimpleBlock.php \Drupal\social_simple\Plugin\Block\SocialSimpleBlock::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/ SocialSimpleBlock.php, line 144
Class
- SocialSimpleBlock
- Provides a 'SocialSimpleBlock' block.
Namespace
Drupal\social_simple\Plugin\BlockCode
public function build() {
$build = [];
$title = $this->configuration['social_share_title'];
$networks = array_filter($this->configuration['social_networks']);
if (empty($networks)) {
return $build;
}
/* @TODO Find a generic way to fetch from the route the entity its belongs.
* If the entity is an instance of ContentEntityInterface.
*/
$entity = NULL;
if ($node = $this->currentRouteMatch
->getParameter('node')) {
$entity = $node;
}
elseif ($taxonomy_term = $this->currentRouteMatch
->getParameter('taxonomy_term')) {
$entity = $taxonomy_term;
}
if (!$entity) {
$keys = $this->currentRouteMatch
->getParameters()
->keys();
$entity_type_id = isset($keys[0]) ? $keys[0] : '';
if (!empty($entity_type_id)) {
$current_entity = $this->currentRouteMatch
->getParameter($entity_type_id);
if ($current_entity instanceof ContentEntityInterface) {
$entity = $current_entity;
}
}
}
$build = $this->socialSimpleGenerator
->buildSocialLinks($networks, $title, $entity);
return $build;
}