fix error when field definition has changed

This commit is contained in:
Julien Fastré 2019-04-16 15:19:42 +02:00
parent 7568eb9eda
commit 4182c53304
2 changed files with 19 additions and 4 deletions

5
CHANGELOG.md Normal file
View File

@ -0,0 +1,5 @@
Master branch
=============
- fix error on export: error when field definition has changed

View File

@ -361,6 +361,16 @@ class CustomFieldChoice extends AbstractCustomField
}
}
/**
* Return true if the choice given in $choiceSlug is checked inside $data.
*
* Used in list exports.
*
* @param CustomField $cf
* @param string $choiceSlug the slug of the choice we want to know if it was checked
* @param array|string $data the data of the field
* @return boolean
*/
public function isChecked(CustomField $cf, $choiceSlug, $data)
{
if ($data === null) {
@ -369,15 +379,15 @@ class CustomFieldChoice extends AbstractCustomField
if ($cf->getOptions()[self::MULTIPLE]) {
if ($cf->getOptions()[self::ALLOW_OTHER]) {
return \in_array($choiceSlug, $data['_choices']);
return \in_array($choiceSlug, $this->deserialize($data, $cf)['_choices']);
} else {
return \in_array($choiceSlug, $data);
return \in_array($choiceSlug, $this->deserialize($data, $cf));
}
} else {
if ($cf->getOptions()[self::ALLOW_OTHER]) {
return $data['_choices'] === $choiceSlug;
return $this->deserialize($data, $cf)['_choices'] === $choiceSlug;
} else {
return $data === $choiceSlug;
return $this->deserialize($data, $cf) === $choiceSlug;
}
}
}