Page MenuHomePhorge

How does one get the value of a custom field in a custom field extension?
OpenPublic

Asked by keithzg on Aug 13 2024, 20:41.

Details

I'm trying to format a custom field to be displayed in a slightly special manner (simply, I want it to be rendered as a link, for the sake of linking to case numbers in an older bugtracker we're finally migrating away from at my work). Turns out I can easily figure out how to make it look like that . . . but I cannot for the life of me figure out how to include the actual value of the custom field! I see functions for getting the field key and field name, but I need the field value . . .

Answers

aklapper
Updated 33 Days Ago

Per David Walsh quoting @avivey on https://davidwalsh.name/custom-field-values:

function get_custom_field_value($object, $key_field) {
  $field = PhabricatorCustomField::getObjectField(
    $object,
    PhabricatorCustomField::ROLE_DEFAULT,
    $key_field
  );

  id(new PhabricatorCustomFieldStorageQuery())
  ->addField($field)
  ->execute();

  $value = $field->getValueForStorage();

  return $value;
}

New Answer