Get field label in PHP

Hi,

In a custom component I need to display a field label. According to the documentation I can use the "translate" function.
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_12.1/Architecture/Languages/Module_Labels/

But the documentation does not mention how to retrieve the label from a module based on a field name. This is what I got so far:

$labelKey = 'LBL_' . strtoupper($fieldName);
$label = translate($labelKey, $module);

This works for most fields, but the system label can be different from the field name, because this is editable when creating a new field.

So what I would like to do is:

$labelKey = getLabelName($fieldName, $module); // THIS FUNCTION DOES NOT EXIST
$label = translate($labelKey, $module);

Regards,

Stijn

Parents
  • Ok, I figured it out by searching the sugar core php files.

    $emptyBean = BeanFactory::newBean($module);
    $labelKey = $emptyBean->field_defs[$fieldName]['vname'];
    $label = translate($labelKey, $module);

    Hope some one else finds it useful.

Reply
  • Ok, I figured it out by searching the sugar core php files.

    $emptyBean = BeanFactory::newBean($module);
    $labelKey = $emptyBean->field_defs[$fieldName]['vname'];
    $label = translate($labelKey, $module);

    Hope some one else finds it useful.

Children
No Data