Skip to content

User's language is "wrong" in URL-HooksΒ #1871

Open
@BernhardBaumrock

Description

@BernhardBaumrock

Short description of the issue

Use-case: I wanted to create an url-hook to open a PDF or, if any page was saved in the meantime, re-create that pdf on the fly and redirect to that file. The PDF is in english (default) and german.

The problem is that the language of $this->wire->user is always the default language inside the hook!

public function init() {
  wire()->addHook("/create-cv",                 $this, "createCV");
}

public function createCV(HookEvent $event): void
{
  bd($this->wire->user->language); // always the default language!
}

Expected behavior

I'd like to get the user's current language inside the hook via $this->wire->user->language

Workaround

I came up with this workaround:

public function init() {
  wire()->addHook("/create-cv",                 $this, "createCV");
  wire()->addHook("/de/create-cv",              $this, "createCV");
}

public function createCV(HookEvent $event): void
{
  bd($this->wire->user->language); // is now either default or de
}

So that tells me that because the hook is applied to the root-page / PW thinks that the language is always english, but that's not really the case in my scenario.

I understand why it's technically always english, but I think it should be the current language.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions