From dac272b9733c36c7bb94043b586132ebb323a20b Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 18 Aug 2021 12:17:44 +0300 Subject: [PATCH] EASYOPAC-1348 - Show covers by Faust instead of PID. --- ding_language.module | 46 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/ding_language.module b/ding_language.module index 44a88fd..e87fd64 100644 --- a/ding_language.module +++ b/ding_language.module @@ -508,3 +508,49 @@ function ding_language_preprocess_eu_cookie_compliance_popup_info(&$variables) { $variables['agree_button'] = t('OK, I agree'); } } + +/** + * Implements hook_ting_covers(). + */ +function ding_language_ting_covers($entities) { + $covers = []; + $fausts = []; + foreach ($entities as $entity) { + $fausts[$entity->provider_id] = $entity->ding_entity_id; + } + try { + $service = new AdditionalInformationService(variable_get('ting_covers_addi_wsdl_url'), variable_get('ting_covers_addi_username'), variable_get('ting_covers_addi_group'), variable_get('ting_covers_addi_password'), variable_get('ting_covers_addi_enforce_url', FALSE)); + + // Retrieve covers by Faust. + $retrieved = $service->getByFaustNumber(array_keys($fausts)); + + foreach ($retrieved as $pid => $cover) { + // Try to extract the image url from the result. + $source_url = FALSE; + if ($cover->detailUrl) { + $source_url = $cover->detailUrl; + } + elseif ($cover->thumbnailUrl) { + $source_url = $cover->thumbnailUrl; + } + + // If we still haven't found a cover check if we can use external URL. + if (!$source_url && isset($cover->externUrl)) { + $source_url = $cover->externUrl; + } + + if ($source_url) { + // Return the path to the cover. + $covers[$fausts[$pid]] = $source_url; + } + } + } + catch (Exception $exception) { + watchdog('ding_language', 'Unable to retrieve covers from ADDI: %message', ['%message' => $exception->getMessage()], WATCHDOG_ERROR); + + // Error in fetching, return no covers. + return []; + } + + return $covers; +}