0

In the weather module, if a user has not configured a custom weather block, the block does not display:

/**
 * Implement hook_block_view().
 */
function weather_block_view($delta = '') {
  global $user;
  module_load_include('inc', 'weather', 'weather.common');
  $block = array();
  // Handle the 'system_NUMBER' type of blocks
  if (strpos($delta, '_') === FALSE) {
    $display_type = $delta;
  }
  else {
    list($display_type, $display_number) = explode('_', $delta);
  }
  $forecast_days = (int) variable_get('weather_forecast_days', '2');
  switch ($display_type) {
    case 'user':
      if (weather_access_userblock()) {
        // Show the user's custom weather block, if there is already
        // a place configured. Otherwise, do not show the block.
        $places = weather_get_places_in_use('user', $user->uid);
        if (!$places) {
          return;
        }
        ...
        [from weather.module]

Is there a way of displaying a 'Please set your weather location' link, instead of nothing at all, without applying a patch to the module?

Thanks.

2
+50

Use the hook_block_view_MODULE_DELTA_alter in your custom module to display text if user has not configured the custom location.you can access the current user object from global $user if you want to perform any operation on it.

/**
 * Implements hook_block_view_MODULE_DELTA_alter().
 */
function demo_wipe_block_view_weather_user_alter(&$data, $block) {
//Check here that whether user has configured or not. 
  if(!is_array($data)) {
    $data['subject'] = t('Blah Blah Blah!');
    $data['content'] = t('Blah Blah Blah! link');
  }
}

P.S. : I have tested it on php 5.5.3

I think you should also specify this as a feature request in the module issue queue to set default whether location(that should be in admin configuration) on user whether block if user has not configured the block yet.

0

You could just create your own wrapping block. Implement hook_block_view, and call weather_block_view from it.

If you get back a useful response, simply return it as your own blocks output. If you don't, return your own output instead, by generating the appropriate link with l.

-2
  1. Enable PHP Filter module.
  2. Create custom block, add on textarea "Please set your weather location" link , set title to "Weather".
  3. Set PHP visibility for block next code: global $user; $places = weather_get_places_in_use('user', $user->uid); return !$places;

  4. Move block position to under Weather block.

  5. So when user doesn't set Weather, he will see set location link block, otherwise, he will see Weather block. No hacks :)

  • 1
    I strongly object to the recommendation to use the PHP-module, especially when it's done without a big disclaimer that it's a huge security problem and should be avoided. -1 – Letharion Nov 18 '14 at 8:42
  • 1
    I strongly suggest to not use PHP-module on any drupal site and I never used PHP filter on my any drupal site. – Naveen Valecha Nov 18 '14 at 9:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.