Module no longer functions

Created on 18 January 2024, 10 months ago
Updated 17 February 2024, 9 months ago

Problem/Motivation

Apologies if i am simply missing something from the setup...but I cannot get this module to work (other than the 3.0-Alpha release).

With a vanilla Drupal 10 install on PHP 8.2, I followed the base setup instructions in the README after downloading (with composer) and enabling the module:

Base setup:
 1.) Go to /admin/config/user-interface/weather
 2.) Import all weather places to the database (one-time action). This operation can take some time, depending on your system's performance, as more than 14.000 records must be inserted into the database. If you'll click this button again in the future, it will remove all places already imported and perform a new 'clean' import of all places.
 3.) (optionally) Configure default weather display settings, these settings will be inherited by all newly created displays
 4.) Add and configure your first system-wide display
 5.) Add new places to the display
 6.) Clear cache and you will be able to see the new block in the system, created for each weather display.

At this point, I added the new system wide display block to the header region. When attempting to view a node displaying this block the following error is thrown:

The website encountered an unexpected error. Try again later.

TypeError: round(): Argument #1 ($num) must be of type int|float, string given in round() (line 261 of modules/contrib/weather-weather/src/Service/ParserService.php).

This can be addressed by typecasting the variable, as shown here πŸ› error Needs review .

Now when viewing the page again I can see the block, but a number of warnings are thrown which look like:

Warning: Trying to access array offset on value of type null in Drupal\weather\Service\ParserService->updatePlaces() (line 259 of modules/contrib/weather-weather/src/Service/ParserService.php).

and the block does not work. It says "Currently, there is no weather information available."

Working backwards from the block...this output displays when the place.forecasts variable is empty:

<div class="weather">
  {% for place in weather %}
    <p style="clear:left"><strong>{{ place.name }}</strong></p>
    {% if place.forecasts is empty%}
      {{'Currently, there is no weather information available.'|t }}
    {% endif %}

When looking at the weather variable to see how it is set there is a preprocess hook which adds variables in weather.module:

\Drupal::service('weather.theme')->preprocessWeatherVariables($variables);

This then calls getWeather(), which then calls downloadWeather(). This should download forecasts from yr.no and put it into the DB.

When downloadForecast() is called during downloadWeather(), it fires another method getLinkForGeoid() to get the forecasts...but this is an incorrect URL. For Boston, Massachusetts, the URL generated is "http://www.yr.no/place/United_States/Massachusetts/Boston/".

This results in a 404: http://www.yr.no/place/United_States/Massachusetts/Boston/

The manual places add form also says to use this URL structure, i.e.:

but these /places/* urls no longer appear functioning, which, if I understand correctly, means all past versions of this module (including Drupal 7) no longer work OOTB.

The result is an empty forecasts array and no data is found.

When using the most recent alpha release I did not see a UI or mechanism to generate weather places...so you have to use version 2.x to import the places, then update to 3.0-alpha1, clear cache...then the block will function.

Steps to reproduce

Follow setup steps from readme.

  1. Download the module
  2. Enable the module
  3. Run the weather places import
  4. Configure a display for one of the places/locations
  5. Place the block in a visible region for your site
  6. View the page as a front end user to try and view the weather

Proposed resolution

TBD -- is it worth updating / maintaining the 2.x version if the alpha release of 3.x appears to have the functionality we need?

Or is the best approach to just recommend..if on 2.x, make sure to import weather places and then update to the 3.x alpha

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Closed: works as designed

Version

3.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States dan612 Portland, Maine

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024