Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StringTagField: array to string conversion on saving #218

Open
micschk opened this issue Aug 27, 2022 · 1 comment
Open

StringTagField: array to string conversion on saving #218

micschk opened this issue Aug 27, 2022 · 1 comment
Labels

Comments

@micschk
Copy link
Contributor

micschk commented Aug 27, 2022

Array to string conversion on line 296 in .../silverstripe/tagfield/src/StringTagField.php:

289     /**
290      * Ensure that arrays are imploded before being saved
291      *
292      * @return mixed|string
293      */
294     public function dataValue()
295     {
296         return implode(',', $this->value);
297     }

It appears $this->value is either a plain array, or an associative array of Title => Value pairs (when altered) at this point:
print_r($this->value) -> Array ( [0] => Array ( [Title] => one [Value] => one ) )

Seems looping over the items and using the 'Value' if defined, string item itself otherwise, fixes this:

public function dataValue()
{
//        return implode(',', $this->value);
        $values = [];
        foreach($this->value as $string_or_assoc_array_value){
            $values[] = is_array($string_or_assoc_array_value) ? $string_or_assoc_array_value['Value'] : $string_or_assoc_array_value;
        }
        return implode(',', $values);
}

If anyone can reproduce and this quick-fix seems acceptable, I'd be happy to create a PR for it.

@GuySartorelli
Copy link
Member

Please provide steps to reproduce this behaviour.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants