Hello everyone,
I tried to implement an automatic option populating based on the method proposed here. I added a function in my theme.php and use it in a custom blueprint.
The function is:
public static function taxonomyValues(string $taxon, string $fieldType)
{
/** @var Grav */
$grav = Grav::instance();
/** @var Admin */
$admin = $grav['admin'];
$admin->enablePages();
/** @var Taxonomy */
$taxonomy = $grav['taxonomy'];
$keys = $taxonomy->getTaxonomyItemKeys($taxon);
$values = [];
foreach ($keys as $key) {
if ($fieldType === 'select') {
$values[$key] = $key;
} else {
$values[] = [
'text' => $key,
'value' => $key
];
}
}
dump($values);
return $values;
}
It works fine with select, but it doesn’t seem to work with selectize. My yaml look like:
header.test:
type: selectize
autocomplete: on
style: vertical
label: test
data-options@: ['\Grav\Theme\NixTemplate::taxonomyValues', 'artiste','selectize']
validate:
type: commalist
If i dump the $values
in the php, I can see an “array of array”:
array:2 [▼
0 => array:2 [▼
"text" => "artiste1"
"value" => "artiste1"
]
1 => array:2 [▼
"text" => "artiste2"
"value" => "artiste2"
]
]
But if i click in the field in the admin, I can’t see any suggestion of completion, do you know what I am doing wrong?