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

Comments

asherry created an issue. See original summary.

asherry’s picture

StatusFileSize
new2.33 KB
asherry’s picture

StatusFileSize
new1.52 KB

Ugh, I'm sorry. I accidentally included the testing code I was doing in the patch. This patch should work, though there are no tests and it's by no means meant for commit.

petednz’s picture

This has worked for our situation - thank you very much - should i change to RBTC

keshavv’s picture

Status: Active » Reviewed & tested by the community

Worked for me as well, +1 for RTBC

jitendrapurohit’s picture

StatusFileSize
new2.03 KB

This is still an issue with another merge option Count merged unique values of this field.

Have updated the patch to include the fix for this option as well.

mlncn’s picture

Anybody using and fixing the module here want to put in a request to be co-maintainer? (I would but i have too many modules already!)