TypeError: array_values(): Argument #1 ($array) must be of type array, null given in array_values()

Created on 18 January 2024, 11 months ago
Updated 5 September 2024, 4 months ago

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)

๐Ÿ› Bug report
Status

Needs review

Version

3.0

Component

Code

Created by

๐Ÿ‡บ๐Ÿ‡ธUnited States kandugatlasantosh

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @kandugatlasantosh
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States kandugatlasantosh

    Issue with the array null check

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia chetan 11

    chetan 11 โ†’ made their first commit to this issueโ€™s fork.

  • Merge request !19fixed โ†’ (Open) created by chetan 11
  • Issue was unassigned.
  • Status changed to Needs review 11 months ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia chetan 11

    Please check the above MR.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States kandugatlasantosh

    Update with more null check

  • ๐Ÿ‡จ๐Ÿ‡ฆCanada No Sssweat

    The second patch from #6 introduces

    Warning undefined variable $switcher_horizontal_position and $switcher_vertical_position

    $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.

    I have not been able to reproduce the bug. Might want to add the steps to reproduce.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia mdsohaib4242

    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 = [];
    }
    
Production build 0.71.5 2024