Jump to content

Strange behavior of pages in multilang environment


backes
 Share

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

Link to comment
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. ;)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...