Skip to content

Commit

Permalink
MOBILE-4331 url: Fix icon inside url resources
Browse files Browse the repository at this point in the history
  • Loading branch information
crazyserver committed Aug 30, 2023
1 parent bee1456 commit b634f3d
Showing 1 changed file with 40 additions and 5 deletions.
45 changes: 40 additions & 5 deletions src/addons/mod/url/services/handlers/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,51 @@ export class AddonModUrlModuleHandlerService extends CoreModuleHandlerBase imple

if (handlerData.buttons && hideButton !== undefined) {
handlerData.buttons[0].hidden = hideButton;
}

return handlerData;
}

if (module.contents && module.contents[0]) {
const icon = AddonModUrl.guessIcon(module.contents[0].fileurl);
/**
* @inheritdoc
*/
async getIconSrc(module?: CoreCourseModuleData): Promise<string | undefined> {
if (!module) {
return;
}

// Calculate the icon to use.
handlerData.icon = CoreCourse.getModuleIconSrc(module.modname, module.modicon, icon);
let mainFile = module.contents?.[0];

if (!mainFile) {
try {
// Try to get module contents, it's needed to get the URL with parameters.
const contents = await CoreCourse.getModuleContents(
module,
undefined,
undefined,
true,
false,
undefined,
'url',
);

mainFile = contents[0];
} catch {
// Fallback in case is not prefetched.
const mod = await CoreCourse.getModule(module.id, module.course, undefined, true, false, undefined, 'url');

mainFile = mod.contents?.[0];
}
}

return handlerData;
if (!mainFile) {
return;
}

const icon = AddonModUrl.guessIcon(mainFile.fileurl);

// Calculate the icon to use.
return CoreCourse.getModuleIconSrc(module.modname, module.modicon, icon);
}

/**
Expand Down

0 comments on commit b634f3d

Please sign in to comment.