MOBILE-3814 format-text: Do not add external content without site

main
Pau Ferrer Ocaña 2022-03-08 15:51:03 +01:00
parent 9f03a64a85
commit 5f4b250ea4
1 changed files with 9 additions and 3 deletions

View File

@ -113,6 +113,8 @@ export class CoreFormatTextDirective implements OnChanges {
this.afterRender = new EventEmitter<void>();
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);
}