So far, just to test, i created two Data types classes and everything works just fine.
I would just want to see them grouped together in the frontend - under a custom label, like the Value Suggests or Resource that you can see in the attached image. How can i do that? is there some docs for it?
Thanks in advance
DataTypeInterface includes the getOptgroupLabel() method. Simply add this method to your data type classes and return the label of the optgroup, like so:
public function getOptgroupLabel()
{
return 'My optgroup label'; // @translate
}
and i linked some of them in a resource template. Nonetheless i am able to display just the first two from my data_types array in the frontend. The rest are not rendered and i only see the “Add Value” button.
It may be that some of your data types have empty strings as labels. Make sure your data types have unique strings returned from DataTypeInterface::getLabel().
Thanks for answering me again.
Yes all data types have a public function getLabel() which returns a unique string. What is weird is the fact they get “rendered” according to the order in my invokables array. Jut the first two elements get the label and work properly, the other don’t.
E.g.
'invokables' => [
'mydatatype:date' => DataType\Date::class, <- this gets rendered
'mydatatype:occasion' => DataType\Occasion::class, <- this gets rendered
'mydatatype:note' => DataType\Note::class, <- this becomes Add Value
'mydatatype:measure' => DataType\Measure::class, , <- this becomes Add Value
...
If i flip them:
'invokables' => [
'mydatatype:note' =>DataType\Note::class, <- this gets rendered
'mydatatype:measure' => DataType\Measure::class, ,<- this gets rendered
'mydatatype:date' => DataType\Date::class, <- this becomes Add Value
'mydatatype:occasion' => DataType\Occasion::class, <- this becomes Add Value
...
I cannot reproduce the error, nor can I deduce how the error is possible without returning an empty string from getLabel(). There must be some condition that I’m not anticipating, such as an interaction with another module. I’d continue working on it. It may be helpful to refer to custom data types from other modules, such as NumericDataTypes, ValueSuggest, and CustomVocab.