Created on 10 October 2023, about 1 year ago
Updated 12 October 2023, about 1 year ago

Php8.1 gives a warning on the result page:
Warning: drupal_render(): Argument #1 ($elements) must be passed by reference, value given in CurrentSearchItemActiveLinks->execute() (regel 125 van /home/.../modules/current_search_links/plugins/item_active_links.inc).

🐛 Bug report
Status

Needs review

Version

1.0

Component

Code

Created by

🇳🇱Netherlands cmseasy

Live updates comments and jobs are added and updated live.
  • PHP 8.1

    The issue particularly affects sites running on PHP version 8.1.0 or later.

Sign in to follow issues

Comments & Activities

  • Issue created by @cmseasy
  • Assigned to abhishek_virasat
  • @abhishek_virasat opened merge request.
  • Issue was unassigned.
  • Status changed to Needs review about 1 year ago
  • 🇮🇳India abhishek_virasat

    @cmseasy, I have fixed this issue php8.1 warning, please find the attach patch.

  • 🇳🇱Netherlands cmseasy

    Hi abhishek_virasat, thanks for bug fixing this php8 issue.

    After patching with #5 and a CC: on a search page I have two PHP warnings in the logs:

    	Warning: drupal_render(): Argument #1 ($elements) must be passed by reference, value given in CurrentSearchItemActiveLinks->execute() (regel 127 van ../modules/patched/current_search_links/plugins/item_active_links.inc).
    
    
    	Warning: CurrentSearchItemActiveLinks::{closure}(): Argument #1 ($item) must be passed by reference, value given in CurrentSearchItemActiveLinks->execute() (regel 127 van ../modules/patched/current_search_links/plugins/item_active_links.inc).
    
    
  • 🇮🇳India abhishek_virasat

    @cmseasy , thanx for letting me know, definitely I will look into it.

  • @abhishek_virasat opened merge request.
  • 🇮🇳India abhishek_virasat

    @cmseasy, i have fixed issue, please review the MR.

  • 🇳🇱Netherlands cmseasy

    I used the patch from MR.

    I noticed that the active items are gone, not rendered after the patch.
    To render the active items I changed some lines:

    return [
            '#theme' => 'item_list',
            '#items' => array_map(function (&$item) {
              return $item;
            }, $items),
            '#attributes' => ['class' => $classes],
          ];
        }
      }
    

    to

    return [
            '#theme' => 'item_list',
            '#items' => array_map('drupal_render', array_map(function (&$item) {
              return $item;
            }, $items)),   //line136
            '#attributes' => ['class' => $classes],
          ];
        }
      }
    

    The active links are rendered now, see screenshots.
    This part of the code '#items' => array_map('drupal_render', array_map(function (&$item) { is in the origin code in my module, I don't know why, I think the original builders changed it to render the active links.

    In the logs I have now:
    Warning: drupal_render(): Argument #1 ($elements) must be passed by reference, value given in CurrentSearchItemActiveLinks->execute() (regel 136 van ../modules/patched/current_search_links/plugins/item_active_links.inc).
    I marked line 136 above.

    Sorry, I am a websitebuilder not a php coder. Hope you can help here.

  • 🇳🇱Netherlands cmseasy

    And the screenshots

  • 🇮🇳India abhishek_virasat

    @cmseasy, I added new changes in same MR. that will render your active item and warning issue will be fixed. please review the MR.

  • 🇳🇱Netherlands cmseasy

    The rendering of the active items is back and ok now :).

    In php8.1 I still have a log warning:

    Warning: CurrentSearchItemActiveLinks::{closure}(): Argument #1 ($item) must be passed by reference, value given in CurrentSearchItemActiveLinks->execute() (regel 126 van ../modules/patched/current_search_links/plugins/item_active_links.inc).
    

    This is my/your code with line 126 marked

          return [
            '#theme' => 'item_list',
            '#items' => array_map(function (&$item) {
              return drupal_render($item);
            }, $items),               //line 126
            '#attributes' => ['class' => $classes],
          ];
    
        }
      }
    
Production build 0.71.5 2024