You are here

function gravatar_process_default_setting in Gravatar integration 6

Same name and namespace in other branches
  1. 7 gravatar.admin.inc \gravatar_process_default_setting()

Add previews for each default picture option.

1 string reference to 'gravatar_process_default_setting'
gravatar_admin_settings in ./gravatar.admin.inc
Administration settings form.

File

./gravatar.admin.inc, line 81
Administrative page callbacks for the gravatar module.

Code

function gravatar_process_default_setting($element) {
  $element[GRAVATAR_DEFAULT_GLOBAL]['#description'] = t('This setting can be adjusted in the <a href="@user-picture-link">user pictures settings</a>.', array(
    '@user-picture-link' => url('admin/user/settings', array(
      'fragment' => 'edit-user-picture-default',
    )),
  ));

  // If the global user picture is empty, disable the respective option.
  if (!variable_get('user_picture_default', '')) {
    $element[GRAVATAR_DEFAULT_GLOBAL]['#disabled'] = TRUE;
    $element[GRAVATAR_DEFAULT_GLOBAL]['#description'] = t('There currently is not a global default user picture specified.') . ' ' . $element[GRAVATAR_DEFAULT_GLOBAL]['#description'];
  }
  foreach ($element['#options'] as $key => $choice) {

    // Add an image to preview this default image option.
    $options = array(
      'path' => gravatar_get_gravatar(mt_rand(), array(
        'default' => _gravatar_get_default_image($key),
        'force default' => TRUE,
      )),
      'alt' => $choice,
      'title' => $choice,
      'attributes' => array(
        'id' => 'gravatar-imagepreview-' . $key,
        // Hide the image if the respective option is disabled.
        'class' => $choice['#disabled'] ? 'hide' : 'js-hide',
      ),
      'getsize' => FALSE,
    );
    $element[$key]['#suffix'] = theme('image', $options['path'], $options['alt'], $options['title'], $options['attributes'], $options['getsize']);
  }
  return $element;
}