Skip to content

Commit

Permalink
MOBILE-4741 core: Pass lang parameter in iframes too
Browse files Browse the repository at this point in the history
  • Loading branch information
dpalou committed Jan 20, 2025
1 parent 6aff337 commit c8c0edf
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
14 changes: 11 additions & 3 deletions src/core/components/iframe/iframe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { CoreSites } from '@services/sites';
import { toBoolean } from '@/core/transforms/boolean';
import { CoreDom } from '@singletons/dom';
import { CoreAlerts } from '@services/overlays/alerts';
import { CoreLang, CoreLangFormat } from '@services/lang';

@Component({
selector: 'core-iframe',
Expand Down Expand Up @@ -234,9 +235,16 @@ export class CoreIframeComponent implements OnChanges, OnDestroy {
this.displayHelp = CoreIframeUtils.shouldDisplayHelpForUrl(url);

const currentSite = CoreSites.getCurrentSite();
if (this.allowAutoLogin && currentSite) {
// Format the URL to add auto-login if needed.
url = await currentSite.getAutoLoginUrl(url, false);
if (currentSite?.containsUrl(url)) {
// Format the URL to add auto-login if needed and add the lang parameter.
const autoLoginUrl = this.allowAutoLogin ?
await currentSite.getAutoLoginUrl(url, false) :
url;

const lang = await CoreLang.getCurrentLanguage(CoreLangFormat.LMS);
url = CoreUrl.addParamsToUrl(autoLoginUrl, { lang }, {
checkAutoLoginUrl: autoLoginUrl !== url,
});
}

if (currentSite?.isVersionGreaterEqualThan('3.7') && CoreUrl.isVimeoVideoUrl(url)) {
Expand Down
9 changes: 8 additions & 1 deletion src/core/directives/format-text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ import { toBoolean } from '../transforms/boolean';
import { CoreViewer } from '@features/viewer/services/viewer';
import { CorePromiseUtils } from '@singletons/promise-utils';
import { CoreAlerts } from '@services/overlays/alerts';
import { CoreLang, CoreLangFormat } from '@services/lang';

/**
* Directive to format text rendered. It renders the HTML and treats all links and media, using CoreLinkDirective
Expand Down Expand Up @@ -833,7 +834,13 @@ export class CoreFormatTextDirective implements OnChanges, OnDestroy, AsyncDirec
// Remove iframe src, otherwise it can cause auto-login issues if there are several iframes with auto-login.
iframe.src = '';

const finalUrl = await CoreIframeUtils.getAutoLoginUrlForIframe(iframe, src);
let finalUrl = await CoreIframeUtils.getAutoLoginUrlForIframe(iframe, src);

const lang = await CoreLang.getCurrentLanguage(CoreLangFormat.LMS);
finalUrl = CoreUrl.addParamsToUrl(finalUrl, { lang }, {
checkAutoLoginUrl: src !== finalUrl,
});

await CoreIframeUtils.fixIframeCookies(finalUrl);

iframe.src = finalUrl;
Expand Down

0 comments on commit c8c0edf

Please sign in to comment.