After sorting out various other problems, I have now found time for another look at this. I spent some time working my way through Fabrik code, finding an anomaly where getLabelForValue() is called from addLabels(); it failed to find the value supplied and returned instead (as a failure default) the value itself rather than the related text. This was because the list values were integers, whereas the value supplied was a string. getLabelForValue() made the comparison using an array_search call, supplying true as the $strict parameter. When I checked in addLabels(), the value it supplied in the call to getLabelForValue() was an integer; how it arrived as a string, I have no idea. As a test, I modified getLabelForValue() to convert the value back to an integer. This allowed getLabelForValue() to return the required text, but caused problems elsewhere.
I then made some comparisons with the J3/F3 system from which the J4/F4 system had been converted. (Incidentally, I found that there is now a version of JDump that works with J4, which was helpful.) The only changes that had been made to my code were those required for the upgrade. I found that the function I had written to generate options lists from database tables, created an array where the value column was an integer in the F4/J4 system, but a string in J3/F3. Most of the code was identical; the one difference was that the statement that generated each option had been changed from:
$sm_options[] = JHTML::_('select.option', $sm_row->ID, $sm_row->$sm_fieldName);
to:
$sm_options[] = JHtmlSelect:: option($sm_row->ID, $sm_row->$sm_fieldName);
This change was required as the original caused an error and I think it was made by guesswork; the Joomla website is almost devoid of any mention of this feature for J4 - I certainly cannot find any. I had found documentation for the API17 version of the JhtmlSelect:: option (it states that the $value parameter is of type string), but none for J4. Searching Fabrik files, I found, in F4:
a function option() in class Select in namespace Joomla\CMS\HTML\Helpers in libraries/src/HTML/Helpers/Select.php, which includes the comment:
“* @ param string $value The value of the option”.
and, in F3:
a function option() in class JHtmlSelect in libraries/cms/html/select.php, which also includes the comment:
“* @ param string $value The value of the option”.
These seem to be the functions called. The code in the two versions appears to be similar if not identical. It seems that, in J3, it converts the parameter to string if it is supplied as an int, whereas, in J4, it uses whatever is supplied unchanged. I do not know what causes the difference in behaviour - may be the different PHP versions or may be not.
I changed my line of code above to:
$sm_options[] = JHtmlSelect:: option(strval($sm_row->ID), $sm_row->$sm_fieldName);
which solved the problem and has not so far caused any other problem.
At this point, I wondered where I got my original code from. I found it obviously came from the Wiki
Dropdown element which includes very similar code under Sample Eval Populate. This has a note with it “NOTE: Fabrik assumes the select IDs to be strings. Notice the first select option has the zero in quotes. Failing to do this will break the proper display of the value in a list view.” which I must have missed. The sample code actually produces an options list with integer IDs (apart from 'Please select'), but that works anyway in Fabrik 3. Might it be worth modifying the Wiki to include a revised version for Fabrik 4?
PHP:
$options[] = JHtmlSelect::option('0', 'Please select' );
$db = FabrikWorker::getDbo();
$db->setQuery("SELECT id, text FROM #__tablename");
$rows = $db -> loadObjectList();
foreach ($rows as $row) {
$options[] = JHtmlSelect::option(strval($row->id), $row->text);
}
return $options;
Oh well; at least I now know a bit more about how Fabrik works!