Skip to content

fix(core): re-init session and culture in switchContext - #73

Open
Ibochkarev wants to merge 2 commits into
3.xfrom
fix/14962-public-initculture-initsession
Open

fix(core): re-init session and culture in switchContext#73
Ibochkarev wants to merge 2 commits into
3.xfrom
fix/14962-public-initculture-initsession

Conversation

@Ibochkarev

@Ibochkarev Ibochkarev commented Aug 21, 2026

Copy link
Copy Markdown
Member

Что сделано

После успешного switchContext() MODX вызывает _initSession(null), затем _initCulture(null), поэтому cultureKey / locale нового контекста (и опции сессии, когда сессия ещё не активна) вступают в силу.

Также возвращает false, когда $this->context null, вместо fatal на ->key.

Не экспонирует публичные initCulture() / initSession() — это было отвергнуто в ревью; переключение сессии mid-request по-прежнему не рекомендуется, а _initSession остаётся no-op, когда сессия уже инициализирована.

Зачем нужно

Context-routing плагины вызывают switchContext() после оригинального пути init. Без re-init лексикон/locale (а иногда и session enablement через настройки контекста) остаются на предыдущем контексте (modxcms#14962).

Как проверить

  1. Два контекста с разными cultureKey (например en / de).
  2. Из запроса на одном контексте $modx->switchContext('other', true)$modx->cultureKey и лексикон матчат целевой.
  3. phpunit --filter modXSwitchContextCultureTest

Связанные

Refs modxcms#14962

Оригинал: modxcms#16854

Add null check for $this->context before accessing it in switchContext to
prevent errors when context is not initialized. Call _initCulture(null)
after successful context switch so culture/session are re-initialized for
the new context (fixes routing plugins like XRouting).

Refs modxcms#14962
After a successful context switch, call _initSession/_initCulture so
context cultureKey and session options apply without public wrappers.
Guard null context and cover with regression tests (modxcms#14962).
@Ibochkarev Ibochkarev changed the title fix(core): реинициализировать сессию и культуру в switchContext fix(core): re-init session and culture in switchContext Aug 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant