Switch Language Block in Autonav results in 404

Permalink
Good evening

I'm working on a design that calls for the Switch Language functionality to be included in the Autonav. I managed to do that by including a stack in my custom responsive_header_navigation Template. When I now try to switch the language from English to German, I get a 404 "Page Not Found" error.

Funnily enough, when I also add an instance of the Switch Language block to the page for which I'm trying to switch languages, it works i.e. both the block on the page and the block included in the autonav work.

Has anyone else run into this? Does anyone see any obvious problems with my setup, detailed below?

(application/blocks/autonav/templates/responsive_header_navigation/view.php)
...
<div class="ccm-responsive-menu-footer">
 <?php
 $stack = Stack::getByName('Navigation Social Links and Language Switch');
 $stack->display();
 ?>
</div>
...

(The stack also includes the Social Links Block.)


(application/blocks/switch_language/templates/plain_text_links.php)
<?php defined('C5_EXECUTE') or die("Access Denied.");?>
<div class="ccm-block-switch-language-text">
    <?php foreach($languageSections as $ml) { 
       $lang = $ml->getLanguageText($locale);
       ?>
        <a href="<?php echo $view->action('switch_language', $cID, $ml->getCollectionID())?>"
           title="<?php echo $lang;?>"><?php echo $lang;?></a>
           <p><?php echo $cID . ' / ' . $ml->getCollectionName(); ?></p>
    <?php } ?>
</div>


Case 1: On page "Our Service", with Switch Language Block added to page:

URL for English (on page)
http://localhost/c5site/index.php/en/our-service/switch_language/154/183/550

URL for German (on page)
http://localhost/c5site/index.php/en/our-service/switch_language/154/184/550


URL for English (in autonav)
http://localhost/c5site/index.php/en/our-service/switch_language/154/183/347

URL for German (in autonav)
http://localhost/c5site/index.php/en/our-service/switch_language/154/184/347

In this scenario, both blocks work, i.e. the language is switched.


Example: On page "Our Service" with Switch Language Block only present in Autonav:

URL for English
http://localhost/c5site/index.php/en/our-service/switch_language/154/183/347

URL for German
http://localhost/c5site/index.php/en/our-service/switch_language/154/184/347


In this case, even though it's the same URL as above, I get a 404.


Any feedback and hints would be much appreciated :)

 
c5dragon replied on at Permalink Reply
c5dragon
'Hardcoding' this block won't load the JS necessary to switch lang.
By adding it the normal way the JS is included. So both work.
publicb replied on at Permalink Reply
Thanks for taking the time to read my post and answer!

For testing purposes, I tried loading the switch_language block's view.js in the footer, like so:

<script type="text/javascript" src="/c5site/concrete/blocks/switch_language/view.js"></script>


The code in that file seems to only apply to the default view template for the block, which uses a select element:

$(function() {
   $('select[data-select=multilingual-switch-language]').change(function() {
        var action = $(this).attr('data-action').replace('--language--', $(this).val());
        window.location.href = action;
   });
});


I also tried to switch the block's view template to the default one in the stack loaded in my Autonav. The problem persists.

Plus, when I remove the non-hardcoded block from the page again, the problem reappears. Are there other assets associated with this block I should be aware of?
c5dragon replied on at Permalink Reply
c5dragon
Best to create a global area with nav and switch and use css to 'combine' them.

---
In the controller of the switch language block is an asset requirement for the view.
public function view()
{
   $this->requireAsset('javascript', 'jquery');
   ...
}

Depends on the rest of your template/code/blocks if JQ is actually loaded.

But it is probably not going to work:
https://documentation.concrete5.org/developers/working-with-blocks/w...