Jump to content
backes

Strange behavior of pages in multilang environment

Recommended Posts

Hey folks,

I'm working on a multi language site (german=default & english).

I have the strange problem, that the 404 for inactive english pages won't work the way I expected it.

For example:

I enter the following kind of URL in the browser: myurl.com/en/mypageslug/ which is inactive in the backend.

The systems shows me parts of the german page and the language switch is also active on german. If I switch to english it opens the 404 page, which is the right one.

If I log the accessed pages, it shows me the 404 page as url - but the content in the frontend isn't the 404 page! :(

I hope that someone understands the problem and can help me with this strange behavior.

As one check I already wrote a little module to interfere in the pageloading - but it won't do what I want neither...

<?php namespace ProcessWire;

class ProcessLanguageError extends WireData implements Module
{

    public static function getModuleInfo()
    {
        return array(
            'title' => __('LanguageError'),
            'version' => '0.1.0',
            'summary' => __('Throws 404 error if the current page is not accessible in the chosen language.'),
            'autoload' => true,
            'requires' => array('ProcessWire>=3.0.41', 'PHP>=5.6.10')
        );
    }

    /**
     *
     */
    public function init()
    {
        // frontend hooks
        $this->addHookAfter("Page::render", $this, 'hookReturnError');
    }

    /**
     * @throws Wire404Exception
     */
    public function hookReturnError()
    {
        if (!$this->page->viewable($this->user->language)) {
            $this->log('failure');
          // the redirect show only a blank white page without any information...
            $this->session->redirect('http://www.google.de');
            throw new Wire404Exception();
        } else {
            $this->log('yeah baby');
            return;
        }
    }

    public function validatePage($page)
    {
        if(!$page->viewable($this->user->language)) {
            $this->log('error404');
            $this->session->redirect('http://google.de');
            throw new Wire404Exception();
        }
        return false;
    }

}

I appreciate any help!!! Thanks and greetings,

Martin

Share this post


Link to post
Share on other sites

Hi @backes

Is this behavior the same in cases when you logged in to admin panel and logged out? 

Share this post


Link to post
Share on other sites

Does your 404 exception event got thrown if you redirect the session before?

I tested it locally and for me it doesn't get thrown. In my opinion you should either throw the exception or redirect. ;)

Regards, Andreas

Share this post


Link to post
Share on other sites

Thanks @AndZyk,

yeah I know, currently the two lines were only there for testing, should have commented one out before posting! ;)

Share this post


Link to post
Share on other sites

Sorry, if I may not understand you correctly.

But the way your module works right now, you would check if the 404 page is viewable in another language. Because if you try access a non-active page by default a 404 exception gets thrown and your module would hook into the 404 page. So it would be pointless to throw another 404 exception and log it, because that is the default behaviour.

I am not quite sure, what you try to achieve, but if you want to customize your 404 page, you could just create an template and assign it to the 404 page. ;)

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...