Skip to content

Commit

Permalink
Fix compatibility with Kirby 3.8
Browse files Browse the repository at this point in the history
  • Loading branch information
olach committed Oct 7, 2022
1 parent 1b06391 commit 6ebdf1b
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,49 @@
'search' => function (bool $search = false) {
return $search;
}
]
],
'computed' => [
'default' => function (): array {
return $this->toTags($this->default);
},
'value' => function (): array {
return $this->toTags($this->value);
}
],
'methods' => [
'toTags' => function ($value) {
if (is_null($value) === true) {
return [];
}

$options = $this->options();

// transform into value-text objects
return array_map(function ($option) use ($options) {
// already a valid object
if (is_array($option) === true && isset($option['value'], $option['text']) === true) {
return $option;
}

$index = array_search($option, array_column($options, 'value'));

if ($index !== false) {
return $options[$index];
}

return [
'value' => $option,
'text' => $option,
];
}, Str::split($value, $this->separator()));
}
],
'save' => function (array $value = null): string {
return A::join(
A::pluck($value, 'value'),
$this->separator() . ' '
);
},
]
]
]);

0 comments on commit 6ebdf1b

Please sign in to comment.