MOBILE-4407 url: Fix icon inside url resources
This commit is contained in:
		
							parent
							
								
									f599185095
								
							
						
					
					
						commit
						55d126ca24
					
				| @ -107,18 +107,59 @@ export class AddonModUrlModuleHandlerService extends CoreModuleHandlerBase imple | ||||
| 
 | ||||
|         if (handlerData.buttons && hideButton !== undefined) { | ||||
|             handlerData.buttons[0].hidden = hideButton; | ||||
| 
 | ||||
|             if (module.contents && module.contents[0]) { | ||||
|                 const icon = AddonModUrl.guessIcon(module.contents[0].fileurl); | ||||
| 
 | ||||
|                 // Calculate the icon to use.
 | ||||
|                 handlerData.icon = CoreCourse.getModuleIconSrc(module.modname, module.modicon, icon); | ||||
|         } | ||||
| 
 | ||||
|         try { | ||||
|             handlerData.icon = await this.getIconSrc(module); | ||||
|         } catch { | ||||
|             // Ignore errors.
 | ||||
|         } | ||||
| 
 | ||||
|         return handlerData; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * @inheritdoc | ||||
|      */ | ||||
|     async getIconSrc(module?: CoreCourseModuleData): Promise<string | undefined> { | ||||
|         if (!module) { | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|         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]; | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         if (!mainFile) { | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|         const icon = AddonModUrl.guessIcon(mainFile.fileurl); | ||||
| 
 | ||||
|         // Calculate the icon to use.
 | ||||
|         return CoreCourse.getModuleIconSrc(module.modname, module.modicon, icon); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Returns if contents are loaded to show link button. | ||||
|      * | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user