function sharebar_preprocess_region in ShareBar 8
Same name and namespace in other branches
- 7 sharebar.module \sharebar_preprocess_region()
Preprocess variables for region.tpl.php
File
- ./
sharebar.module, line 55 - Allows site owner to add share buttons on their website
Code
function sharebar_preprocess_region(&$variables) {
$args = explode('/', current_path());
//print_r($args); die;
$is_node = FALSE;
if ($node = \Drupal::routeMatch()
->getParameter('node')) {
if ($args[0] == 'node' && is_numeric($args[1]) && !isset($args[2])) {
$is_node = TRUE;
}
$node_type = $node
->bundle();
}
if ($variables['region'] == 'sidebar_first') {
if ($args[0] != 'admin') {
if ($is_node && \Drupal::config('sharebar.settings')
->get('sharebar_bar_posts_' . $node_type . '_enabled') || !($args[0] == 'node' && is_numeric($args[1])) && $args[1] != 'add' && $args[2] != 'edit' && $args[3] != 'edit' && \Drupal::config('sharebar.settings')
->get('sharebar_bar_pages_enabled')) {
$strh = '';
$sbg = \Drupal::config('sharebar.settings')
->get('sharebar_bar_background');
$sborder = \Drupal::config('sharebar.settings')
->get('sharebar_bar_border');
if (\Drupal::config('sharebar.settings')
->get('sharebar_bar_oncontent')) {
if (\Drupal::config('sharebar.settings')
->get('sharebar_bar_position') == 'left') {
$mar = ' margin-right:' . \Drupal::config('sharebar.settings')
->get('sharebar_bar_rightoffset') . 'px;';
}
else {
$mar = ' margin-left:' . \Drupal::config('sharebar.settings')
->get('sharebar_bar_leftoffset') . 'px;';
}
//$cls = 'sharebarp';
$cls = \Drupal::config('sharebar.settings')
->get('sharebar_bar_idcontent');
$sty = 'width: ' . \Drupal::config('sharebar.settings')
->get('sharebar_bar_swidth') . 'px; float: ' . \Drupal::config('sharebar.settings')
->get('sharebar_bar_position') . ';' . $mar;
}
else {
//$cls = 'sharebar';
$cls = \Drupal::config('sharebar.settings')
->get('sharebar_bar_id');
$settings['cls'] = "#" . $cls;
_drupal_add_js(array(
'sharebar' => $settings,
), 'setting');
$sty = '';
}
$str = '<ul id="' . $cls . '" style="background:#' . $sbg . ';border-color:#' . $sborder . ';margin-top:' . \Drupal::config('sharebar.settings')
->get('sharebar_bar_toptoffset') . 'px;' . $sty . '">';
$buttons = unserialize(\Drupal::config('sharebar.settings')
->get('sharebar_buttons'));
if (empty($buttons)) {
$buttons = unserialize(sharebar_buttons_def());
}
if (is_array($buttons) && count($buttons)) {
usort($buttons, "sharebar_cmp_up");
foreach ($buttons as $key => $value) {
if ($value->enabled) {
$str .= '<li>' . sharebar_bar_filter($value->big_button, \Drupal::service("title_resolver")
->getTitle(\Drupal::request(), \Drupal::routeMatch()
->getRouteObject())) . '</li>';
//print_r($str);
//echo "here"; die;
}
if ($value->enabled && \Drupal::config('sharebar.settings')
->get('sharebar_bar_horizontal') && !\Drupal::config('sharebar.settings')
->get('sharebar_bar_oncontent')) {
$strh .= '<li>' . sharebar_bar_filter($value->small_button, \Drupal::service("title_resolver")
->getTitle(\Drupal::request(), \Drupal::routeMatch()
->getRouteObject())) . '</li>';
}
}
}
$str .= '</ul>';
if (\Drupal::config('sharebar.settings')
->get('sharebar_bar_horizontal')) {
$hrcls = \Drupal::config('sharebar.settings')
->get('sharebar_bar_idhorizontal');
$settings['hrcls'] = "#" . $hrcls;
_drupal_add_js(array(
'sharebar' => $settings,
), 'setting');
$str .= '<ul id="' . $hrcls . '"' . $strh . '</ul>';
}
$variables['sharebar'] = $str;
// . $variables['content'];
}
}
}
}