Retrieve Custom Field Values for Phabricator Objects

By  on  

Phabricator is an incredibly well-coded PHP application but lacks a bit on the documentation side.  Then again, what open source project isn't?  Over the past months I've been slowly integrating Phabricator, a newish review tool, with Bugzilla, a much older tool.  The most recent step saw me needing to add a custom field (DifferentialCommitMessageCustomField class extension) to revisions:

Phabricator Bug ID

Creating the DifferentialCommitMessageCustomField extension was fairly simple but, due to the structure of DifferentialRevision and other Phabricator classes, retrieving that field value isn't as easy as one would hope.  After trying a variety of methods and combing through the classes chain source code, it was Aviv Eyal that provided a nice utility function for retrieving custom field data for a given Phabricator object type:

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;
}

In my case, the $object was a DifferentialRevision and the $key_field is differential:bugzilla-bug-id, defined within my DifferentialCommitMessageCustomField extension.  If you are adding a CustomField of any kind to any Phabrication application, you can use this same method.

When documentation is lacking and inheritance levels a dozen levels deep, it's great that community members can jump in to help each other -- it speaks volumes for the project.

Recent Features

  • By
    CSS Animations Between Media Queries

    CSS animations are right up there with sliced bread. CSS animations are efficient because they can be hardware accelerated, they require no JavaScript overhead, and they are composed of very little CSS code. Quite often we add CSS transforms to elements via CSS during...

  • By
    How I Stopped WordPress Comment Spam

    I love almost every part of being a tech blogger:  learning, preaching, bantering, researching.  The one part about blogging that I absolutely loathe:  dealing with SPAM comments.  For the past two years, my blog has registered 8,000+ SPAM comments per day.  PER DAY.  Bloating my database...

Incredible Demos

  • By
    Hot Effect: MooTools Drag Opacity

    As you should already know, the best visual features of a website are usually held within the most subtle of details. One simple trick that usually makes a big different is the use of opacity and fading. Another awesome MooTools functionality is...

  • By
    Scroll IFRAMEs on iOS

    For the longest time, developers were frustrated by elements with overflow not being scrollable within the page of iOS Safari.  For my blog it was particularly frustrating because I display my demos in sandboxed IFRAMEs on top of the article itself, so as to not affect my site's...

Discussion

    Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!