From 5f4b250ea49e25b670b615127a52d2205a7e7650 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Tue, 8 Mar 2022 15:51:03 +0100 Subject: [PATCH] MOBILE-3814 format-text: Do not add external content without site --- src/core/directives/format-text.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/core/directives/format-text.ts b/src/core/directives/format-text.ts index ef15c4f68..a879c3c83 100644 --- a/src/core/directives/format-text.ts +++ b/src/core/directives/format-text.ts @@ -113,6 +113,8 @@ export class CoreFormatTextDirective implements OnChanges { this.afterRender = new EventEmitter(); this.element.addEventListener('click', this.elementClicked.bind(this)); + + this.siteId = this.siteId || CoreSites.getCurrentSiteId(); } /** @@ -144,9 +146,13 @@ export class CoreFormatTextDirective implements OnChanges { * Apply CoreExternalContentDirective to a certain element. * * @param element Element to add the attributes to. - * @return External content instance. + * @return External content instance or undefined if siteId is not provided. */ - protected addExternalContent(element: Element): CoreExternalContentDirective { + protected addExternalContent(element: Element): CoreExternalContentDirective | undefined { + if (!this.siteId) { + return; + } + // Angular doesn't let adding directives dynamically. Create the CoreExternalContentDirective manually. const extContent = new CoreExternalContentDirective(new ElementRef(element)); @@ -459,7 +465,7 @@ export class CoreFormatTextDirective implements OnChanges { this.addMediaAdaptClass(img); const externalImage = this.addExternalContent(img); - if (!externalImage.invalid) { + if (externalImage && !externalImage.invalid) { externalImages.push(externalImage); }