Files
lichterei-web/kirby/config/fields/mixins/options.php
Bastian Allgeier 01277f79f2 first version
2019-01-13 23:17:34 +01:00

44 lines
1.3 KiB
PHP
Executable File

<?php
use Kirby\Form\Options;
return [
'props' => [
/**
* API settings for options requests. This will only take affect when <code>options</code> is set to <code>api</code>.
*/
'api' => function ($api = null) {
return $api;
},
/**
* An array with options
*/
'options' => function ($options = []) {
return $options;
},
/**
* Query settings for options queries. This will only take affect when <code>options</code> is set to <code>query</code>.
*/
'query' => function ($query = null) {
return $query;
},
],
'methods' => [
'getOptions' => function () {
return Options::factory(
$this->options(),
$this->props,
$this->model()
);
},
'sanitizeOption' => function ($option) {
$allowed = array_column($this->options(), 'value');
return in_array($option, $allowed, true) === true ? $option : null;
},
'sanitizeOptions' => function ($options) {
$allowed = array_column($this->options(), 'value');
return array_intersect($options, $allowed);
},
]
];