Faster - probably, but cleaner I don't think.
Within your code I see that you've got a field "goods" which is a select, then you have to format good's name and it's category.
You should know about description_callback. It's a method that will be called to format default linked label.
I assume that your code now is (with function header):
function display_goods($record, $nolink) {
$goods_id = $record->goods; // record is Item
$goods_rs = new Custom_Goods_Recordset();
$goods = $goods_rs->get_record($goods_id);
$goods_link = $goods->record_link($goods->name, $nolink);
$category_id = $goods->category;
$category_rs = new Custom_Category_Recordset();
$category_link = $category_rs->create_linked_label('name', $category_id, $nolink);
return "$goods_link [$category_link]";
}
You could create a description callback for goods (in Custom_Goods_Recordset class):
static function default_label($record, $nolink) {
$goods_link = $record->record_link($record->name, $nolink);
$category_id = $record->category;
$category_rs = new Custom_Category_Recordset();
$category_link = $category_rs->create_linked_label('name', $category_id, $nolink);
return "$goods_link [$category_link]";
}
Register description callback in the install file:
$goods_rs = new Custom_Goods_Recordset();
$goods_rs->install(); // that's what you should have
// that's new
$goods_rs->set_description_callback(array('Custom_Goods_Recordset', 'default_label'));
And now your display callback for the goods field will look like this:
$goods_id = $record->goods; // record is Item
$goods_rs = new Custom_Goods_Recordset();
return $goods_rs->create_default_linked_label($goods_id);
Regards,
Adam 😉