TypeError: array_values(): Argument #1 ($array) must be of type array, null given in array_values() (line 385 of modules/contrib/gtranslate/src/Plugin/Block/GTranslateBlock.php).
Drupal\gtranslate\Plugin\Block\GTranslateBlock->build() (Line: 138)
Drupal\twig_tweak\View\BlockViewBuilder->build('gtranslate_block', Array, ) (Line: 147)
Drupal\twig_tweak\TwigTweakExtension::drupalBlock('gtranslate_block', Array, ) (Line: 763)
__TwigTemplate_48ffa98a1a0529e691df516cd18744f0->doDisplay(Array, Array) (Line: 394)
Twig\Template->displayWithErrorHandling(Array, Array) (Line: 367)
Twig\Template->display(Array) (Line: 379)
Twig\Template->render(Array, Array) (Line: 40)

Issue fork gtranslate-3415650

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

  • 3415650- Comparechanges, plain diff MR !19
  • 3415650-1 Comparecompare

Comments

kandugatlasantosh created an issue. See original summary.

kandugatlasantosh’s picture

StatusFileSize
new911 bytes

Issue with the array null check

chetan 11 made their first commit to this issue’s fork.

chetan 11’s picture

Assigned: kandugatlasantosh » Unassigned
Status: Active » Needs review

Please check the above MR.

kandugatlasantosh’s picture

StatusFileSize
new2 KB

Update with more null check

no sssweat’s picture

The second patch from #6 introduces

Warning undefined variable $switcher_horizontal_position and $switcher_vertical_position


Lets analyze:

$float_position = $settings->get('float_position');

Float position will never be an array and will always be a string since you can only select one. Therefore,

if(is_array($float_position)){

Is not necessary and it's introducing the undefined variables, as it will never pass this check.

Use the first patch from comment #2 if anything.

mdsohaib4242’s picture

This worked for me.

// Check if $languages is an array before using array_values()
$languages = $settings->get('languages');
if (is_array($languages)) {
    $languages = array_filter(array_values($languages), function($l) {
        return !empty($l);
    });
} else {
    $languages = [];
}
vagelis-prokopiou’s picture

This worked for me:

--- ./GTranslateBlock.php	2025-01-19 11:15:27.000725955 +0200
+++ html/modules/contrib/gtranslate/src/Plugin/Block/GTranslateBlock.php	2025-01-19 11:15:54.316640455 +0200
@@ -383,7 +383,7 @@
         $url_structure = $settings->get('url_structure');
         $custom_domains = $settings->get('custom_domains');
         $custom_domains_config = $settings->get('custom_domains_config');
-        $languages = array_values(array_filter(array_values($settings->get('languages')), function($l) {return !empty($l);}));
+        $languages = array_values(array_filter(array_values($settings->get('languages') ?? []), function($l) {return !empty($l);}));
         $custom_css = $settings->get('custom_css');
         $enable_cdn = $settings->get('enable_cdn');
 
@@ -440,4 +440,4 @@
 
         return $return;
     }
-}
\ No newline at end of file
+}

Module version: 3.0.4
PHP: 8.3

jquijano made their first commit to this issue’s fork.

kolesnikoff’s picture

StatusFileSize
new1.04 KB

Patch based on the comment #9

dburiak’s picture

Status: Needs review » Needs work

The patch #11 can't be applied to gtranslate 3.0.5.