You are here

function sharebar_bar_filter in ShareBar 8

Same name and namespace in other branches
  1. 6 sharebar.module \sharebar_bar_filter()
  2. 7.2 sharebar.module \sharebar_bar_filter()
  3. 7 sharebar.module \sharebar_bar_filter()

Replaces dynamic data with their values.

1 call to sharebar_bar_filter()
sharebar_preprocess_region in ./sharebar.module
Preprocess variables for region.tpl.php

File

./sharebar.module, line 147
Allows site owner to add share buttons on their website

Code

function sharebar_bar_filter($input, $title = '') {
  $args = explode('/', current_path());
  $name = '';
  if ($args[0] == 'node' && is_numeric($args[1])) {
    $node = \Drupal::routeMatch()
      ->getParameter('node');
    if ($node->nid > 0) {
      $title = $node
        ->getTitle();
      $name = $node
        ->getOwner()
        ->getUsername();
    }
  }
  $path = isset($_GET['q']) ? $_GET['q'] : '<front>';
  $currenturl = \Drupal::URL($path, [], [
    'absolute' => TRUE,
  ]);
  $code = array(
    '[title]',
    '[url]',
    '[author]',
    '[twitter]',
  );
  $values = array(
    $title,
    $currenturl,
    $name,
    \Drupal::config('sharebar.settings')
      ->get('sharebar_bar_twitter_username'),
  );
  return str_replace($code, $values, $input);
}