- Issue created by @dpi
- ๐ฆ๐บAustralia dpi Perth, Australia
As discovered by https://git.drupalcode.org/project/pusher_mini/-/merge_requests/1
- ๐ฎ๐ณIndia aditi saraf
Aditi Saraf โ made their first commit to this issueโs fork.
- ๐ฎ๐ณIndia samir_shukla bareilly
Hi, created the patch for the issue. Please review.
- Status changed to Needs review
over 1 year ago 5:06am 30 January 2024 - last update
over 1 year ago 8 pass - First commit to issue fork.
- ๐ฎ๐ณIndia rajeshreeputra Pune
Changes are available in 1.20 release.
- Merge request !39Fix: Key::setKeyValue can accept array, documented as only accepting string. โ (Open) created by rajeshreeputra
- ๐บ๐ธUnited States cmlara
This method can in fact accept arrays for use with multi-value keys.
Can it ?
KeyTypeMultivalueInterface calls for a serialize method to be present which allows converting the multiple value to string. To me that would imply that these should only be strings by the time it reaches the storage layer.
This sounds more like the referenced project was actually using the Key module outside the API and PHPstan correctly flagged it.
Needs work for method signature change, though I believe this is more likley works as designed.
- ๐บ๐ธUnited States japerry KVUO
This issue highlights a broken architectural decision, where the underlying setKeyValue method, which IS a string, has a hard-coded override injected into it where it diverts to a plugin if the multivalue setting is enabled. Not great.
However, neither the patch or the MR would work in the 8.x-1.x branch. Key's own tests show that setKeyValue is supposed to accept an array. See https://git.drupalcode.org/project/key/-/blob/8.x-1.x/tests/src/Kernel/K...
So for 8.x-1.x, yes, this does need to accept both a string and array because.. reasons. Its not great but it is needed. But https://git.drupalcode.org/project/key/-/blob/8.x-1.x/src/Entity/Key.php... isn't sufficient, as you could end up calling this method and NOT have multivalue set, then you're storing an array when the actual value ($this->keyValue) can only accept a string.
Personally, I'd rip out the plugin definition logic and and just json_encode on array, removing the deferral to the plugin. (Especially as both MultiValueKeyType and AuthenticationMultiValueKeyType 'serialize' method just calls json_encode anyway)