Merge unique issue with in_array values

Created on 24 February 2023, over 1 year ago
Updated 10 April 2024, 7 months ago

Problem/Motivation

Merge unique does not seem to be working. All of the rest of the merge types work, it is ... uniquely... the unique merge type.

Steps to reproduce

When I debug the preRenderMergeUnique function here:

if (!empty($rendered_row[$field_name]) && !\in_array($rendered_row[$field_name], $merged_row[$field_name])) {
  $merged_row[$field_name][] = $rendered_row[$field_name];
}

It's doing an in_array with an array of \Drupal\Core\Render\Markup objects. I believe this in_array comparison with the strict setting will always return FALSE.

Example:

$needle = t('Test');
$haystack = [t('Test')];
$result1 = in_array($needle, $haystack); // Returns TRUE
$result2 = in_array($needle, $haystack, TRUE); // Returns FALSE

$needle = 'Test';
$haystack = ['Test'];

$result3 = in_array($needle, $haystack); // Returns TRUE
$result4 = in_array($needle, $haystack, TRUE); // Returns TRUE

Proposed resolution

I have a patch that just adds another function to convert the markup objects to strings. This isn't the best solution, but I need it for now.

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

RTBC

Version

2.0

Component

Miscellaneous

Created by

🇺🇸United States asherry

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

Comments & Activities

Production build 0.71.5 2024