From b9850b08dc66d2c5704493adc38c950f8a2fc362 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Thu, 7 Nov 2019 11:41:19 +0100 Subject: [PATCH] MOBILE-2235 core: Fix site.getid() exceptions due to format text --- src/components/site-picker/site-picker.ts | 2 +- src/directives/format-text.ts | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/components/site-picker/site-picker.ts b/src/components/site-picker/site-picker.ts index dca537560..60bfd17e5 100644 --- a/src/components/site-picker/site-picker.ts +++ b/src/components/site-picker/site-picker.ts @@ -51,7 +51,7 @@ export class CoreSitePickerComponent implements OnInit { sites.forEach((site: any) => { // Format the site name. promises.push(this.filterProvider.formatText(site.siteName, {clean: true, singleLine: true, filter: false}, [], - site.getId()).catch(() => { + site.id).catch(() => { return site.siteName; }).then((siteName) => { site.fullNameAndSiteName = this.translate.instant('core.fullnameandsitename', diff --git a/src/directives/format-text.ts b/src/directives/format-text.ts index 54e627c9f..9c4a8c314 100644 --- a/src/directives/format-text.ts +++ b/src/directives/format-text.ts @@ -404,7 +404,10 @@ export class CoreFormatTextDirective implements OnChanges { // Error getting the site. This probably means that there is no current site and no siteId was supplied. }).then((siteInstance: CoreSite) => { site = siteInstance; - result.siteId = site.getId(); + + if (site) { + result.siteId = site.getId(); + } if (this.contextLevel == 'course' && this.contextInstanceId <= 0) { this.contextInstanceId = site.getSiteHomeId(); @@ -422,14 +425,14 @@ export class CoreFormatTextDirective implements OnChanges { if (this.filter) { return this.filterHelper.getFiltersAndFormatText(this.text, this.contextLevel, this.contextInstanceId, - result.options, site.getId()).then((res) => { + result.options, result.siteId).then((res) => { result.filters = res.filters; return res.text; }); } else { - return this.filterProvider.formatText(this.text, result.options, [], site.getId()); + return this.filterProvider.formatText(this.text, result.options, [], result.siteId); } }).then((formatted) => {