eZ Community » Forums » eZ Publish 5 Platform » LanguageSwitcher - Legacy module...
expandshrink

LanguageSwitcher - Legacy module 'test' doesn't exist. Cannot generate URL

LanguageSwitcher - Legacy module 'test' doesn't exist. Cannot generate URL

Friday 17 April 2015 4:46:51 pm - 8 replies

Hi,

I use the LanguageSwitch of eZDemoBundle. When i try to make a 404 error (exemple with /test). I have this error :

An exception has been thrown during the rendering of a template ("Legacy module 'test' doesn't exist. Cannot generate URL."blunk.gif Emoticon in MyBaseBundle:parts:languages_switcher.html.twig at line 16.

This is this line ({{ url( routeRef ) }}) :

https://github.com/ezsystems/Demo...rts/languages_switcher.html.twig#L20 

I think that i need to test if is a known module before ? So how ? There is a function for this ?
Thanks 

Saturday 18 April 2015 6:56:06 pm

Hello Johann,

I've actually manually get the same error when trying to use the twig function 'url' to render a link in a custom template to 'content2/download' (so not based on current page url or dynamic in any way) when building a custom bundle recently.

I was just testing that my template change was being used, which the error proved so I quickly reverted the 'content2' module uri name change and moved on with my work.

I keep reading and re-reading your original post trying to think of how I could help and I came up with a question that if you answer might help all of us make better suggestions.

Question: Was the web browser on the page uri /test when you got the error in question? Or where where you manually entering /test uri within some part of eZ, if so which part specifically?

I currently do not know of any non-legacy way to test if a module is active before using it.

While I actually do not think you need to test if a module is active before trying to use it (even with the limited information you shared) you might be able to create a custom twig function which calls the legacy kernel to use the php class which provides the end functionality of the 'ezmodule' operator (or just reimplement what the code does in a simpler way):

https://github.com/ezsystems/ezpublish-legacy/blob/master/kernel/common/ezmoduleoperator.php#L45

https://doc.ez.no/eZ-Publish/Technical-manual/4.x/Reference/Template-operators/Data-and-information-extraction/ezmodule

https://github.com/ezsystems/ezpublish-legacy/blob/master/doc/features/3.10/ezmodule_template_operator.txt

Sorry I do not know enough about how the new stack eZDemoBundle LanguageSwitcher solution works to give more accurate responses.

I hope this helps!

Cheers,
Heath

Monday 20 April 2015 12:06:14 pm

Hi, @Heath, just to be sure, that content2/download is a custom module you have? it's a legacy one? 

Monday 20 April 2015 12:13:35 pm

Hello there.

It sounds to me that this could be a valid bug. Not entirely sure what we should do with the error, but the LanguageSwitcher might benefit from special handling of this case.

Tuesday 21 April 2015 12:09:00 pm

Hi @Carlos

You miss-understand me, content2/download was an intentional template edit typo I made during replacement of the legacy template which generates links to content/download with a twig replacement while creating a custom bundle.

I made the typo to know that the template was being used. I learned like Johann that you can not link to a module view uri using the twig url function (currently) without generating an error if the module does not exist.

I hope I'm being more clear, I fear I'm merely repeating myself.

Best wishes!

Cheers,
Heath

Tuesday 21 April 2015 12:14:40 pm

Understood now, sorry. 

As Bertrand says this probably needs some work. Maybe we could move some logic to the controller and play with try, catch blocks and don't print the links to other languages/siteaccess if they don't exists... 

Tuesday 28 April 2015 5:35:37 pm

In fact, i don't want to add a new module. In my exemple i used "test" but i could used "dfjdhfhdslfhdsb" with the same result.

My goal was to test a 404 error. If i remove my language switcher it's ok (error 40 ezpublish). But with it, i have the error reported in my first post.

I search to skip this line with url() function. 

Tuesday 28 April 2015 10:32:55 pm

Hello Johann,

I know that you were not trying to add a new module and I understand now you were just trying to make an error appear. I think the short term lesson here is ... don't do that, IE: force an error in dev unless you want the current results. IE: Don't try to link to things which don't exist :\

Though I agree with Carlos that I think the current results could be much nicer if they didn't do what they currently do. Perhaps I'm wrong and the current error is the best result to make sure the developer does not do things like this (force an error by linking to content / controllers which do not exist). I'm not so sure from a purist standpoint but from the newbie perspective this does seem a little excessive.

I wonder what this test case does in a pure ezplatform (no legacy dependencies) setup?

Cheers,
Heath

Wednesday 29 April 2015 10:37:10 am

Ok,

i add a test in my controller just before return to my template in the LanguageSwitcherController.php :

if (isset($routeReference->getParams()["module_uri"])) {
 return $this->render( 'TemplateWithoutUrlFunction');
}else{
return $this->render( MyBaseBundle:parts:languages_switcher.html.twig',   array(                    'routeRef' => $routeReference,                    'siteaccess' => $siteaccess,                    'currentLanguage' => $currentEzLanguage,                    'availableLanguages' => $availableLanguages                )            );
}

I am aware that this is not the best solution, but it suits me.

Modified on Wednesday 29 April 2015 10:37:56 am by Johann Roc

expandshrink

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

36 542 Users on board!

Forums menu

Proudly Developed with from