function sharethis_comment_view in ShareThis 8.2
Same name and namespace in other branches
- 7.2 sharethis.module \sharethis_comment_view()
Implements hook_ENTITY_TYPE_view().
File
- ./
sharethis.module, line 162 - A module that adds one of the ShareThis widget to your website.
Code
function sharethis_comment_view(array &$build, EntityInterface $comment, EntityViewDisplayInterface $display, $view_mode) {
$sharethis_manager = \Drupal::service('sharethis.manager');
$sharethis_settings = \Drupal::config('sharethis.settings');
if ($sharethis_settings
->get('comments') == 1) {
$st_js = $sharethis_manager
->sharethisIncludeJs();
$data_options = $sharethis_manager
->getOptions();
$current_url = Url::fromRoute('<current>');
$current_url
->setOptions([
'absolute' => TRUE,
'fragment' => 'comment-' . $comment
->id(),
]);
$path = $current_url
->toString();
$request = \Drupal::request();
$route_match = \Drupal::routeMatch();
$title = \Drupal::service('title_resolver')
->getTitle($request, $route_match
->getRouteObject());
$content = $sharethis_manager
->renderSpans($data_options, $title, $path);
$build['sharethis'] = [
'#theme' => 'sharethis_block',
'#content' => $content,
'#attached' => [
'library' => [
'sharethis/sharethispickerexternalbuttonsws',
'sharethis/sharethispickerexternalbuttons',
'sharethis/sharethis',
],
'drupalSettings' => [
'sharethis' => $st_js,
],
],
'#attributes' => [
'class' => 'sharethis-comment',
],
'#weight' => $sharethis_settings
->get('location'),
];
}
}