Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 48 additions & 40 deletions FieldtypeSelectExtOption.module
Original file line number Diff line number Diff line change
Expand Up @@ -624,46 +624,54 @@ class FieldtypeSelectExtOption extends FieldtypeMulti {
*/
protected function getEqualValue(Page $page, Field $field, $value) {

// receive current page value (SelectExtOption or SelectExtOptionArray) from data array
$_value = isset($page->data[$field->name]) ? $page->data[$field->name] : null;
if (!$_value) return $value;

// $this->error('changed');

$int1 = null;
$int2 = null;
$array1 = [];
$array2 = [];

// $this->error('changed');

if ($value instanceof SelectExtOption) $int1 = $value->value;
if ($value instanceof SelectExtOptionArray) $array1 = array_values($value->each('value'));

if ($_value instanceof SelectExtOption) $int2 = $_value->value;
if ($_value instanceof SelectExtOptionArray) $array2 = array_values($_value->each('value'));

if (is_numeric($value)) $int1 = (int) $value;
if (is_array($value)) {
foreach ($value as $key => $item) {
if ($item instanceof SelectExtOption) $array1[] = $item->value;
else if (is_numeric($item)) $array1[] = (int) $item;
}
}

$array1 = array_unique($array1);
$array2 = array_unique($array2);

// sortable?
$module = $this->modules->get($field->input_type);
$sortable = ($module instanceof InputfieldHasArrayValue && $module instanceof InputfieldHasSortableValue)? true : false;
if (!$sortable) {
sort($array1);
sort($array2);
}

if ($array1 === $array2 && $int1 === $int2) return $_value;
return $value;
// receive current page value (SelectExtOption or SelectExtOptionArray) from data array
$_value = isset($page->data[$field->name]) ? $page->data[$field->name] : null;
if (!$_value) return $value;

$int1 = null;
$int2 = null;
$array1 = [];
$array2 = [];

if ($value instanceof SelectExtOption) {
$int1 = $value->value;
} elseif ($value instanceof SelectExtOptionArray) {
foreach ($value as $item) {
$array1[] = $item->value;
}
} elseif (is_array($value)) {
foreach ($value as $item) {
if ($item instanceof SelectExtOption) {
$array1[] = $item->value;
} elseif (is_numeric($item)) {
$array1[] = (int)$item;
}
}
} elseif (is_numeric($value)) {
$int1 = (int)$value;
}

if ($_value instanceof SelectExtOption) {
$int2 = $_value->value;
} elseif ($_value instanceof SelectExtOptionArray) {
foreach ($_value as $item) {
$array2[] = $item->value;
}
}

$array1 = array_unique($array1);
$array2 = array_unique($array2);

// sortable?
$module = $this->modules->get($field->input_type);
$sortable = ($module instanceof InputfieldHasArrayValue && $module instanceof InputfieldHasSortableValue) ? true : false;
if (!$sortable) {
sort($array1);
sort($array2);
}

if ($array1 === $array2 && $int1 === $int2) return $_value;
return $value;
}

public function getBlankValue(Page $page, Field $field) {
Expand Down