Lots of duplicated code in this function. Consider making a function which accepts
$form['avatar_driver']->select('avatar_driver_gravatar');
$form['avatar_gravatar_email']->setValue('test@example.com');
$form['avatar_gravatar_width']->setValue(80);
$form['avatar_gravatar_height']->setValue(80);
as parameters?