function hybridauth_widget_pre_render in HybridAuth Social Login 7.2
Pre-render callback for the 'hybridauth_widget' element.
1 string reference to 'hybridauth_widget_pre_render'
- hybridauth_element_info in ./
hybridauth.module - Implements hook_element_info().
File
- ./
hybridauth.module, line 321 - Main file for the HybridAuth module.
Code
function hybridauth_widget_pre_render($element) {
$query = $element['#hybridauth_query'];
$element['#hybridauth_destination'] = trim($element['#hybridauth_destination']);
$element['#hybridauth_destination_error'] = trim($element['#hybridauth_destination_error']);
// Process destinations; HTTP_REFERER is needed for widget in modals
// to return to the current page.
foreach (array(
'destination',
'destination_error',
) as $key) {
if ($element['#hybridauth_' . $key] == '[HTTP_REFERER]' && isset($_SERVER['HTTP_REFERER'])) {
// We need to make this link relative, see https://www.drupal.org/node/2616284.
global $base_root, $base_path;
$path = str_replace($base_root . $base_path, '', $_SERVER['HTTP_REFERER']);
// Remove language prefix if the site is multilingual.
if (drupal_multilingual()) {
list(, $path) = language_url_split_prefix($path, language_list());
}
$query += array(
$key => $path,
);
}
elseif ($element['#hybridauth_' . $key]) {
$query += array(
$key => $element['#hybridauth_' . $key],
);
}
else {
$destination = drupal_get_destination();
$query += array(
$key => $destination['destination'],
);
}
}
$element['#hybridauth_query'] = $query;
$element['providers'] = array();
switch ($element['#hybridauth_widget_type']) {
case 'list':
$class = array(
'hybridauth-widget-provider',
);
$rel = array(
'nofollow',
);
foreach (hybridauth_get_enabled_providers() as $provider_id => $provider_name) {
$window_type = variable_get('hybridauth_provider_' . $provider_id . '_window_type', 'current');
$window_width = variable_get('hybridauth_provider_' . $provider_id . '_window_width', 800);
$window_height = variable_get('hybridauth_provider_' . $provider_id . '_window_height', 500);
$query_mod = $element['#hybridauth_query'];
$class_mod = $class;
$rel_mod = $rel;
switch ($window_type) {
case 'colorbox':
$class_mod[] = 'colorbox-load';
$query_mod += array(
'width' => $window_width,
'height' => $window_height,
'iframe' => 'true',
);
break;
case 'shadowbox':
$rel_mod = array(
'shadowbox;width=' . $window_width . ';height=' . $window_height,
'nofollow',
);
break;
case 'fancybox':
$class_mod[] = 'fancybox';
$class_mod[] = 'fancybox.iframe';
$class_mod[] = '{width:' . $window_width . ',height:' . $window_height . '}';
break;
case 'lightbox2':
$rel_mod = array(
'lightframe[|width:' . $window_width . 'px; height:' . $window_height . 'px;]',
'nofollow',
);
break;
}
// Determine onclick behavior.
$onclick = '';
if ($element['#hybridauth_onclick'] === FALSE) {
}
elseif (!empty($element['#hybridauth_onclick'])) {
$onclick = $element['#hybridauth_onclick'];
}
elseif ($window_type == 'current') {
$class_mod[] = 'hybridauth-onclick-current';
}
elseif ($window_type == 'popup') {
$class_mod[] = 'hybridauth-onclick-popup';
}
$text = array(
'#theme' => 'hybridauth_provider_icon',
'#icon_pack' => $element['#hybridauth_widget_icon_pack'],
'#provider_id' => $provider_id,
'#provider_name' => $provider_name,
);
$path = 'hybridauth/window/' . $provider_id;
$url = url($path, array(
'query' => $query_mod,
));
if ($element['#hybridauth_widget_hide_links']) {
$path = 'user';
}
$options = array(
'html' => TRUE,
'query' => $query_mod,
'attributes' => array(
'title' => $provider_name,
'class' => $class_mod,
'rel' => $rel_mod,
'data-hybridauth-provider' => $provider_id,
'data-hybridauth-url' => $url,
// jQuery Mobile compatibility - so it doesn't use AJAX.
'data-ajax' => 'false',
// Add authentication window width and height.
'data-hybridauth-width' => $window_width,
'data-hybridauth-height' => $window_height,
) + ($onclick ? array(
'onclick' => $onclick,
) : array()),
);
$element['providers'][$provider_id] = array(
'text' => $text,
'path' => $path,
'options' => $options,
);
}
break;
case 'button':
case 'link':
$provider_id = 'none';
$class = array();
if ($element['#hybridauth_widget_use_overlay']) {
$class = array(
'ctools-use-modal',
'ctools-modal-hybridauthmodal',
);
ctools_include('modal');
ctools_modal_add_js();
$settings = array(
'hybridauthmodal' => array(
'modalSize' => array(
'type' => 'scale',
'width' => '400px',
'height' => '200px',
'addWidth' => 0,
'addHeight' => 0,
'contentRight' => 25,
'contentBottom' => 45,
),
'modalTheme' => 'HybridAuthModalDialog',
// 'throbberTheme' => 'HybridAuthModalThrobber',
'modalOptions' => array(
'opacity' => 0.55,
'background' => '#000',
),
'animation' => 'fadeIn',
'animationSpeed' => 'slow',
'closeText' => t('Close'),
'closeImage' => '',
),
);
$element['#attached']['js'][] = array(
'data' => $settings,
'type' => 'setting',
);
}
$text = $element['#hybridauth_widget_link_text'];
if ($element['#hybridauth_widget_type'] == 'button') {
$text = array(
'#theme' => 'hybridauth_provider_icon',
'#icon_pack' => $element['#hybridauth_widget_icon_pack'],
'#provider_id' => $provider_id,
'#provider_name' => $element['#hybridauth_widget_link_title'],
);
}
$path = 'hybridauth/providers/nojs/' . $element['#hybridauth_widget_icon_pack'];
$options = array(
'html' => TRUE,
'query' => $element['#hybridauth_query'],
'attributes' => array(
'title' => $element['#hybridauth_widget_link_title'],
'class' => $class,
'rel' => array(
'nofollow',
),
),
);
$element['providers'][$provider_id] = array(
'text' => $text,
'path' => $path,
'options' => $options,
);
break;
}
_hybridauth_add_icon_pack_files($element['#hybridauth_widget_icon_pack'], $element);
return $element;
}