You are here

public function SocialSharingButtonsBlock::build in Better Social Sharing Buttons 8.3

Same name and namespace in other branches
  1. 8 src/Plugin/Block/SocialSharingButtonsBlock.php \Drupal\better_social_sharing_buttons\Plugin\Block\SocialSharingButtonsBlock::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/SocialSharingButtonsBlock.php, line 180

Class

SocialSharingButtonsBlock
Provides a social sharing buttons block.

Namespace

Drupal\better_social_sharing_buttons\Plugin\Block

Code

public function build() {
  $items = [];
  global $base_url;
  $config = $this->configFactory
    ->get('better_social_sharing_buttons.settings');
  $request = $this->requestStack
    ->getCurrentRequest();
  if ($route = $request->attributes
    ->get(RouteObjectInterface::ROUTE_OBJECT)) {
    $title = $this->titleResolver
      ->getTitle($request, $route);
  }
  if ($this->routeMatch
    ->getRouteName() == "entity.user.canonical" && isset($title['#markup'])) {
    $title = $title['#markup'];
  }
  $items['page_url'] = Url::fromRoute('<current>', [], [
    'absolute' => TRUE,
  ]);
  $items['description'] = '';
  $items['title'] = Html::escape($title);
  $items['width'] = $this->configuration['width'] ?? $config
    ->get('width');
  $items['radius'] = $this->configuration['radius'] ?? $config
    ->get('radius');
  $items['facebook_app_id'] = $this->configuration['facebook_app_id'] ?? $config
    ->get('facebook_app_id');
  $items['print_css'] = $this->configuration['print_css'] ?? $config
    ->get('print_css');
  $items['iconset'] = $this->configuration['iconset'] ?? $config
    ->get('iconset');
  $items['services'] = $this->configuration['services'] ?? $config
    ->get('services');
  $items['base_url'] = $base_url;
  return [
    '#theme' => 'better_social_sharing_buttons',
    '#items' => $items,
  ];
}