The function getAvailableGlobalTokens in class DataExport (src/Plugins/views/display/DataExport.php) contains an array union operator.
public function getAvailableGlobalTokens($prepared = FALSE, array $types = []) {
$types += ['date'];
return parent::getAvailableGlobalTokens($prepared, $types);
}
This does not deliver the expected array merge result (refer to https://www.php.net/manual/en/language.operators.array.php), but rather the elements from the right hand array are appended to the left hand (ie original) array where they have a different key. Therefore if the argument $types passed into the function above has the value "['site', 'view']", the resulting $types array will be "['site', 'view']". This is not what is required.
The function should use an array_merge as follows:
public function getAvailableGlobalTokens($prepared = FALSE, array $types = []) {
$types = array_unique(array_merge($types, ['date']));
return parent::getAvailableGlobalTokens($prepared, $types);
}
There may well be other instances of incorrect use of the array union operator in the module.
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | 3152272-views_data_export-4.patch | 558 bytes | jayelless |
| #3 | 3152272-views_data_export-3.patch | 542 bytes | jayelless |
Comments
Comment #2
jayelless commentedComment #3
jayelless commentedPatch attached.
Comment #4
jayelless commentedIt is useful to add an additional set of tokens relating to "current-user" to the available global tokens so I have prepared a revised patch to achieve that.
Comment #5
andreasderijckeThe array_unique in the patch isn't really required, because in the base class
array_flip($types)is called which will eliminate any duplicates.In anyway, the patch works.
This aside, having an event to be able to attach other tokens types would be nice, so you don't need patches to add your own.
Comment #6
andreasderijckeComment #7
andreasderijckeComment #8
andreasderijckeComment #9
steven jones commentedI think we should change the line to something like this:
I.e. just fix the original problem. We can introduce other tokens in other issues etc.
I note that until #3152267: Invalid use of array union operator is sorted this won't make much of a difference anyway.
Comment #11
steven jones commented