I’m building a component and I’m stuck on the properties. If you look at the code below, you’ll see two properties: contentType and tagCategories.
The component UI fails to load properly if tagCategories is present. When I remove it, it works fine.
It seems to be an issue with the checkboxlist type or optionsMethod as I can change the type to something else and there are no issues.
I’ve tried logging in getTagCategoryOptions() and it’s not getting called at all, so something is causing problems.
public function defineProperties()
{
return [
'contentType' => [
'title' => 'Content Type',
'description' => 'Specify whether this is for Blog or Success Story',
'type' => 'dropdown',
'default' => 'blog',
'options' => ['blog' => 'Blog', 'success_story' => 'Success Story']
],
'tagCategories' => [
'title' => 'Tag Categories',
'description' => 'Select the tag categories to display',
'type' => 'checkboxlist',
'optionsMethod' => 'getTagCategoryOptions'
]
];
}
public function getTagCategoryOptions()
{
$categories = TagCategory::orderBy('name')->pluck('name', 'slug')->toArray();
return $categories ?? [];
}
I’ve also tried this code as well after desperately asking ChatGPT, but still no luck:
public function defineProperties()
{
return [
'contentType' => [
'title' => 'Content Type',
'description' => 'Specify whether this is for Blog or Success Story',
'type' => 'dropdown',
'default' => 'blog',
'options' => ['blog' => 'Blog', 'success_story' => 'Success Story']
],
'tagCategories' => [
'title' => 'Tag Categories',
'description' => 'Select the tag categories to display',
'type' => 'checkboxlist'
]
];
}
public function getPropertyOptions($property)
{
if ($property === 'tagCategories') {
return TagCategory::orderBy('name')->pluck('name', 'slug')->toArray();
}
return [];
}
Any help much appreciated!