Skip to content

Commit

Permalink
Enum search fix
Browse files Browse the repository at this point in the history
  • Loading branch information
vldiark committed Mar 25, 2019
1 parent b719098 commit 2e58bf3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/Base/Models/CustomField/MultiSelectField.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function setValues(Array $values)
$values = array_unique(array_merge($this->getValues(), $values));
$enums = [];
foreach($values as $value) {
$enum = array_search($value, (array)$this->field->enums);
$enum = array_search($value, get_object_vars($this->field->enums));
if ($enum === false) {
throw new \Exception('Invalid value: "'.$value.'" for cfield "'.$this->name.'" (enum not found)');
}
Expand All @@ -86,6 +86,9 @@ public function setEnums(Array $enums)
$enums = array_unique(array_merge($this->getEnums(), $enums));
$new_values = [];
foreach ($enums as $enum) {
if (!array_key_exists($enum, get_object_vars($this->field->enums))) {
throw new \Exception('Invalid enum: "'.$enum.'" for cfield "'.$this->name.'" (not found)');
}
$new_values[$enum]= (object)[
'enum' => $enum,
'value' => $this->field->enums->{$enum}
Expand Down
4 changes: 2 additions & 2 deletions src/Base/Models/CustomField/SelectField.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function getEnum()
*/
public function setValue($value)
{
$enum = array_search($value, (array)$this->field->enums);
$enum = array_search($value, get_object_vars($this->field->enums));
if ($enum === false) {
throw new \Exception('Invalid value: "'.$value.'" for cfield "'.$this->name.'" (enum not found)');
}
Expand All @@ -40,7 +40,7 @@ public function setValue($value)
*/
public function setEnum($enum)
{
if (!array_key_exists($enum, (array)$this->field->enums)) {
if (!array_key_exists($enum, get_object_vars($this->field->enums))) {
throw new \Exception('Invalid enum: "'.$enum.'" for cfield "'.$this->name.'" (not found)');
}
$this->values = [
Expand Down

0 comments on commit 2e58bf3

Please sign in to comment.