drupalwxt / wxt

Drupal 10 variant of the Web Experience Toolkit (WxT).
https://drupalwxt.github.io
GNU General Public License v2.0
25 stars 27 forks source link

Language Detection and Selection warning with loss of language toggle #150

Closed mankev closed 5 years ago

mankev commented 5 years ago

In Language Detection and Selection after deselecting Detection Method = URL (in order to use Browser language detection) there is a loss of language toggle on site pages and the following warning is displayed: "Warning: Attempt to modify property 'links' of non-object in Drupal\wxt_library\Plugin\Block\LanguageBlock->build() (line 154 of modules\custom\wxt_library\src\Plugin\Block\LanguageBlock.php). "

Release = 2.2.14 Theme = WxT Usability or Canada.ca (others not tested) php = 7.1

I did some debugging but I am not sure what it the code is supposed to do. (my comments)

Code snippet from affected code // Don't show current language in toggle. *(Is the loss of language toggle by design?) $toggle = FALSE; foreach ($config['language_toggle'] as $enabled) { if ($enabled === $wxt_active) { $toggle = TRUE; } } ($enable=0, $wxt-active = "theme-gcweb")****

if (!$toggle) {
  unset($links->links[$language]); ***(Line 154 $toggle = FALSE, $links=null)****
}

When Detection Method = URL deselected $links= null (causes the error)

When Detection Method = URL selected (no error) {#6724 ▼ +"links": array:2 [▼ "en" => array:5 [▼ "url" => Url {#6455 ▶} "title" => "English" "language" => ConfigurableLanguage {#6444 ▶} "attributes" => array:1 [▶] "query" => [] ] "fr" => array:5 [▼ "url" => Url {#5341 ▶} "title" => "French" "language" => ConfigurableLanguage {#6527 ▶} "attributes" => array:1 [▶] "query" => [] ] ] +"method_id": "language-url" }

$config array:6 [▼ "id" => "wxt_language_block:language_interface" "label" => "WxT Language switcher" "provider" => "wxt_library" "label_display" => "visible" "wxt_theme" => false "language_toggle" => array:6 [▼ "theme-base" => "theme-base" "theme-ogpl" => "theme-ogpl" "theme-wet-boew" => 0 "theme-gcwu-fegc" => 0 "theme-gc-intranet" => 0 "theme-gcweb" => 0 ] ]


sylus commented 5 years ago

Think this just needs some sort of guard logic, and the actual unsetting is cause otherwise both languages show up English (no link) and French if on a english page and vice versa for French.

sylus commented 5 years ago

Added a guard and wrote a more apt description of what am doing ^_^

Thanks so much for patience :D