You are here

function sharethis_block_output in Sharethis block 7

Returns a render array with the block output and library attached.

Return value

array The render array for the block.

1 call to sharethis_block_output()
sharethis_block_block_view in ./sharethis_block.module
Implements hook_block_view().

File

./sharethis_block.module, line 104
Hook implementations for the sharethis_block module.

Code

function sharethis_block_output() {
  $product_type = 'sop';

  // If inline buttons have been chosen then there is some actual markup
  // which is used to place the buttons on the page.
  if (variable_get('sharethis_inline', FALSE)) {
    $build['buttons'] = [
      '#markup' => '<div class="sharethis-inline-share-buttons"></div>',
    ];
    $product_type = 'inline-share-buttons';
  }

  // Get the product ID configured in the block settings.
  $property_id = variable_get('sharethis_property_id', '');

  // Attach the javascript with the correct variables.
  drupal_add_js("//platform-api.sharethis.com/js/sharethis.js#property={$property_id}&product={$product_type}", [
    'type' => 'external',
    'scope' => 'footer',
  ]);

  // The sharethis theme needs to be used for this block to minimise markup.
  $build['#theme'] = 'block__sharethis';
  return $build;
}