You are here

function ulogin_widget_pre_render in uLogin (advanced version) 7

Pre-render callback for the 'ulogin_widget' element.

1 string reference to 'ulogin_widget_pre_render'
ulogin_element_info in ./ulogin.module
Implements hook_element_info().

File

./ulogin.module, line 244
Main file for the uLogin module.

Code

function ulogin_widget_pre_render($element) {
  $element['#ulogin_id'] = drupal_html_id($element['#ulogin_id']);
  $element['#attached']['js'][] = array(
    'type' => 'setting',
    'data' => array(
      'ulogin' => array(
        $element['#ulogin_id'],
      ),
    ),
  );
  if ($element['#ulogin_widget_id']) {
    $element['#theme'] = 'ulogin_widget_id';
    return $element;
  }
  if ($element['#ulogin_redirect']) {
    $callback = 'Drupalulogintoken';
    $redirect = '';
    $element['#attached']['js'][drupal_get_path('module', 'ulogin') . '/js/ulogin.js'] = array(
      'type' => 'file',
    );
  }
  else {
    $callback = '';
    $redirect = _ulogin_token_url($element['#ulogin_destination']);
  }
  $element['#ulogin_data'] = 'display=' . $element['#ulogin_display'] . ';fields=' . $element['#ulogin_fields_required'] . ';optional=' . $element['#ulogin_fields_optional'] . ';callback=' . $callback . ';redirect_uri=' . $redirect;
  if ($element['#ulogin_display'] == 'window') {
    $element['#theme'] = 'ulogin_widget_window';
    return $element;
  }
  if ($element['#ulogin_display'] == 'buttons') {
    $element['#theme'] = 'ulogin_widget_buttons';
    $icons = array();
    if (!empty($element['#ulogin_icons_path'])) {
      foreach (file_scan_directory($element['#ulogin_icons_path'], '//') as $icon) {
        $icons[$icon->name] = $icon->uri;
      }
    }
    if (empty($icons)) {
      $icons = $element['#ulogin_icons'];
    }
    $element['icons'] = array();
    foreach ($icons as $key => $value) {
      $image_info = image_get_info($value);
      $element['icons'][] = array(
        '#theme' => 'image',
        '#path' => $value,
        '#alt' => $key,
        '#title' => $key,
        '#width' => $image_info['width'],
        '#height' => $image_info['height'],
        '#attributes' => array(
          'data-uloginbutton' => $key,
          'class' => 'ulogin-icon-' . $key,
        ),
      );
    }
    return $element;
  }
  $element['#ulogin_data'] .= ';providers=' . $element['#ulogin_providers'] . ';hidden=' . $element['#ulogin_hidden'];
  return $element;
}