Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
This project is not covered by Drupal’s security advisory policy.
This module is NOT an official one and uses AEMET, Agencia Estatal de Metereología, data from their OpenData API.
Sky icons get from weather_es module.
This enables the AEMET PHP API and a simple block to show weather information.
API call example in aemet/src/Plugin/Block/SimpleAemetWeatherBlock::build()
/**
* {@inheritdoc}
*/
public function build() {
try {
// Module configuration.
$modSettings = $this->configFactory->get('aemet.settings');
// Prepare AEMET API configuration.
$aemetCfg = new Configuration();
$aemetCfg->setApiKey('api_key', $modSettings->get('api_key'));
// Call authorization endpoint.
$pred = new PrediccionesEspecificasApi(NULL, $aemetCfg);
$mod200 = $pred->prediccinPorMunicipiosDiariaTiempoActual_($this->configuration['city']);
// Call authorized endpoint to get real data.
// @see $this->aemetValues->getFinalMetaData($mod200); response to
// get help.
$data = $this->aemetValues->getFinalData($mod200);
// @todo: Build block.
$build['content'] = [
'#markup' => $this->t('It works!'),
];
}
catch (\Exception $e) {
$build = [];
$this->logger->alert($this->t('Remote call error "@message" in line @line of @file: @trace', [
'@message' => $e->getMessage(),
'@file' => $e->getFile(),
'@line' => $e->getLine(),
'@trace' => $e->getTraceAsString(),
]));
}
return $build;
}
The simple block allow alter her city:
/**
* Allow alter the configured city to show.
*
* @param string $cityToShow
* The actual city code.
*/
function hook_aemet_block_city_alter(&$cityToShow) {
// Show Almonte weather.
// The code is the province ID, 21 to Huelva,
// and de city code, 005 to Almonte.
$cityToShow = '21005';
}
Supporting organizations:
Project information
- Seeking new maintainer
The current maintainers are looking for new people to take ownership. - Module categories: Integrations, Developer Tools
- 1 site reports using this module
- Created by psf_ on , updated
- This project is not covered by the security advisory policy.
Use at your own risk! It may have publicly disclosed vulnerabilities.