eZ Community » Forums » eZ Publish 5 Platform » Always available flag set on content...
expandshrink

Always available flag set on content seems not respected

Always available flag set on content seems not respected

Friday 25 September 2015 5:43:52 pm - 6 replies

Hi there,

Hope somebody can shed a light on this.

I have a content I wish to show ONLY in 'fre-FR'. The content is added in this language, no other translations exist. The "Use the main language if there is no prioritized translation. " is unchecked - marking it NOT ALWAYS AVAILABLE. (at least that's what I think it implies.)

However, it is also found and displayed when I browse the page in 'fre-CA', because the following languages are configured for Canadian French:

  fr_ca:
            languages:
                - fre-CA
                - fre-FR
                - eng-INT

Shouldn't the UrlAliasService know about my current locale and respect the Always Available flag?

Or am I misunderstanding this feature?

Thanks in advance for pointing me to a direction.

(ezpublish 5.3 EE)

Modified on Monday 28 September 2015 4:32:23 pm by Andras Debreczeni

Friday 25 September 2015 9:56:01 pm

Hi Andras,

You are misunderstanding this a bit. The fre-FR is in the priority list, so the content will be shown in that siteaccess. The "Use the main language if there is no prioritized translation. " would control the situation if the fre-FR (the only local of that content) was not in the priority list.

Modified on Friday 25 September 2015 9:56:32 pm by Ivo Lukač

Monday 28 September 2015 9:07:52 am

Thanks Ivo,

Do you have a suggestion on how to achieve something like this then without handling it via a custom controller?

Monday 28 September 2015 11:03:03 am

Quote from Andras Debreczeni :

Thanks Ivo,

Do you have a suggestion on how to achieve something like this then without handling it via a custom controller?

You want to hide only that one content in fre-FR for the Canadian site? The fre-FR is shown on the rest of the site?

Monday 28 September 2015 2:37:30 pm

Exactly. That content should throw a 404 in fre-CA. It should only be rendered if the locale is exactly what we specified (=fre-FR).

Obviously the 404 works already for example ger-DE.

The rest of the site should be displayed as it is now (mostly all other content is also defined in the default english language)

Monday 28 September 2015 2:51:04 pm

Quote from Andras Debreczeni :

Exactly. That content should throw a 404 in fre-CA. It should only be rendered if the locale is exactly what we specified (=fre-FR).

Obviously the 404 works already for example ger-DE.

The rest of the site should be displayed as it is now (mostly all other content is also defined in the default english language)

The problem is that prioritised language list is the strongest here. Probably not a viable solution but you could remove the fre-FR from that list and then  mark all other fre-FR content to "Use the main language..."

Monday 28 September 2015 4:35:53 pm

Thanks for confirming this.

I ended up dispatching a PRE_CONTENT_VIEW listener which will trigger my custom 'Not-Always-Available' logic.

Namely, this listener checks if the the flag is unset and if the current request language is among the current content's languageCodes. If not, throw 404 accordingly.

If somebody is looking for the same solution, this is the simple logic I used:

   * @param PreContentViewEvent $view
     * @DI\Observe(MVCEvents::PRE_CONTENT_VIEW)
     */
    public function onPreContentView(PreContentViewEvent $view)
    {
        /** @var Content $content */
        $content = $view->getContentView()->getParameter('content');
 
        // only trigger if the alwaysAvailable flag is unset
        // this is the 'Use the main language if there is no prioritized translation' checkbox found under Translations.
        if (0 === $content->contentInfo->alwaysAvailable) {
            $currentLocale = $this->localeConverter->convertToEz($this->request->getLocale());
            // the content's version info contains the actual translations the current content is translated into.
            if (false === in_array($currentLocale, $content->getVersionInfo()->languageCodes)) {
                throw new NotFoundHttpException('This content is not available in your language.');
            }
        }
    }

Modified on Monday 28 September 2015 4:37:09 pm by Andras Debreczeni

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from