Class should not have a theming function, and it's calling drupal_add_css, which is already called in the template file.
We should remove the theme function in the class, remove drupal_add_css in tpl file and add a preprocess function .module file to add the css when a google_weather block is displayed
(I think this is the right place to add the css in our case, although I'm not completely sure, as there are so many places to use drupal_add_css()):

/**
 * Main function to make call to google weather service using cURL lib.
 */
function google_weather_show($location) {
	if (!isset($location) && !is_object($location)) {
		return;
	}

	$id = isset($location->bid) ? "bid_$location->bid" : "uid_$location->uid";
	$cache = cache_get('google_weather_' . $id, 'cache_block');
	// Return cache if possible, and if expiration time is still more than current time.
	if (!empty($cache) && isset($cache->data) && ($cache->expire > time())) {
		return $cache->data;
	}

  // no cache, generate the output.
  global $language;
  $weather = new googleWeather($location, $language);
  $data = theme('google_weather_block', $weather->data);

	// Cache for x time (settings).
	cache_set('google_weather_' . $id, $data, 'cache_block',
		time() + variable_get('google_weather_block_cache', 3600));

	return $data;
}

function google_weather_preprocess_block(&$vars){
  if($vars['elements']['#block']->module == 'google_weather'){
    drupal_add_css(drupal_get_path('module', 'google_weather') . '/google_weather.css');
  }
}

If agree, I can create the patch.

Comments

damiankloip’s picture

I wasn't sure about that either :) The only thing I am weary of is that it needs to be easy for people to override the css. If it's added in the preprocess function people would have to override everything to re theme the block rather than start a fresh. I agree it should move out of the class though.

hles’s picture

That's right for the css, I think the best way to go is to provide users with very general/basic css to start with. That way, they will likely add css styles, rather than overwriting the current ones.

damiankloip’s picture

Status: Active » Closed (fixed)