Problem/Motivation
For field types that have values represented by multidimensional arrays, FieldItemList::equals() may return a false-positive due to limitations in comparing arrays with the == operator.
E.g.:
$a = array (
0 =>
array (
'plugin_configuration' =>
array (
'id' => 'block_content:2508dfc8-ba47-4995-a6e2-080b7c6be903',
'label' => 'Copyright something4',
'provider' => 'block_content',
'label_display' => 0,
'status' => true,
'info' => '',
'view_mode' => '',
),
'plugin_id' => 'block_content:2508dfc8-ba47-4995-a6e2-080b7c6be903',
),
);
$b = array (
0 =>
array (
'plugin_configuration' =>
array (
'id' => 'block_content:2508dfc8-ba47-4995-a6e2-080b7c6be903',
'label' => 'Copyright something4',
'provider' => 'block_content',
'label_display' => 'visible',
'status' => true,
'info' => '',
'view_mode' => '',
),
'plugin_id' => 'block_content:2508dfc8-ba47-4995-a6e2-080b7c6be903',
),
);
drush_log('Truth: ' . print_r($a==$b, true), 'status');
Note the label_display value is different, however the comparison in the test returns true/1.
Proposed resolution
There are a few potential solutions, e.g. I am using `serialize()` to flatten the values for comparison in a contrib module, however this is likely to have a significant performance hit versus the current operator.
Remaining tasks
Decide 1) if this is a bug in the eyes of the core maintainers and 2) determine a more reliable and backwards-compatible method of determining equality. It could be that such field types may just need to override this method, and that's the decision.
User interface changes
None.
API changes
None.
Data model changes
None.
Comments
Comment #2
bradjones1Comment #3
idebr commentedThis will probably be fixed in one of the related issues.
Comment #4
bradjones1