function avatar_selection_validate_user_avatar in Avatar Selection 6
Same name and namespace in other branches
- 7 avatar_selection.module \avatar_selection_validate_user_avatar()
Validate and upload the user's picture.
Parameters
&$form: General reference used in drupal, defining the structure & the fields of a form.
&$form_state: General reference, used to control the processing of the form.
2 string references to 'avatar_selection_validate_user_avatar'
- avatar_selection_form_user_profile_form_alter in ./
avatar_selection.module - Implementation of hook_form_alter().
- avatar_selection_form_user_register_alter in ./
avatar_selection.module - Implementation of hook_form_alter().
File
- ./
avatar_selection.module, line 319 - The Avatar Selection module allows the user to pick an avatar image from a list already loaded by an administrative user, and to the administrator to disable uploading other avatar files by the user.
Code
function avatar_selection_validate_user_avatar(&$form, &$form_state) {
// If required, validate the uploaded picture.
$validators = array(
'file_validate_is_image' => array(),
'file_validate_image_resolution' => array(
variable_get('user_picture_dimensions', '85x85'),
),
'file_validate_size' => array(
variable_get('user_picture_file_size', 30) * 1024,
),
);
$file = file_save_upload('picture_upload', $validators);
if (!$file && !empty($form_state['values']['select_avatar'])) {
unset($form_state['values']['picture_delete']);
$path = file_create_path('avatar_selection') . '/';
$form_state['values']['picture'] = $path . $form_state['values']['select_avatar'];
}
elseif (!$file && variable_get('avatar_selection_set_random_default', FALSE)) {
if (isset($form_state['values']['_account'])) {
$user = $form_state['values']['_account'];
}
else {
$user = drupal_anonymous_user();
}
if ($user->picture && $form_state['values']['picture_delete'] != 1) {
$form_state['values']['picture'] = $user->picture;
}
else {
unset($form_state['values']['picture_delete']);
$form_state['values']['picture'] = avatar_selection_get_random_image($user);
}
}
}