Diviner

Class DifferentialFieldSpecification

Definedsrc/applications/differential/field/specification/DifferentialFieldSpecification.php:21

Describes and implements the behavior for a custom field on Differential revisions. Along with other configuration, you can extend this class to add custom fields to Differential revisions and commit messages.

Generally, you should implement all methods from the storage task and then the methods from one or more interface tasks.

Tasks

Field Storage

Extending the Revision Edit Interface

Extending the Revision View Interface

Extending the Revision List Interface

Extending the E-mail Interface

Extending the Conduit View Interface

Extending Commit Messages

Loading Additional Data

Contextual Data

Unspecified

search

Methods

public void didParseCommit(PhabricatorRepository $repo, PhabricatorRepositoryCommit $commit, PhabricatorRepositoryCommitData $data)

parametersPhabricatorRepository$repoThe repository the commit appeared in.
PhabricatorRepositoryCommit$commitThe commit itself.
PhabricatorRepostioryCommitData$dataCommit data.
returnvoid

This method allows you to take action when a commit appears in a tracked branch (for example, by closing tasks associated with the commit).

protected didSetRevision()

returnwild
This method is not documented.

public void didWriteRevision(DifferentialRevisionEditor $editor)

parametersDifferentialRevisionEditor$editorActive editor which has just applied changes to the revision.
returnvoid

Hook after an edit operation has completed. This allows you to update link tables or do other write operations which should happen after the revision is saved. Normally you don't need to implement this.

public string getColumnClassForRevisionList()

returnstringCSS class for table cells.

Optionally, return a column class for revision list tables.

public string getCommitMessageKey()

returnstringKey which identifies the field in dictionaries.

Key which identifies this field in parsed commit messages. Commit messages exist in two forms: raw textual commit messages and parsed dictionaries of fields. This method must return a unique string which identifies this field in dictionaries. Principally, this dictionary is shipped to and from arc over Conduit. Keys should be appropriate property names, like "testPlan" (not "Test Plan") and must be globally unique.

You must implement this method if you return true from shouldAppearOnCommitMessage().

public getCommitMessageTips()

returnwild
This method is not documented.

final protected getDiff()

returnwild
This method is not documented.

final public array getDiffProperties()

returnarrayArray of all Diff properties.

Get the list of properties for a diff set by setManualDiff().

final public mixed|null getDiffProperty($key)

parametersstring$keyDiff property key.
returnmixed|nullDiff property, or null if the property does not have a value.

Get a property of a diff set by setManualDiff().

final protected PhabricatorObjectHandle getHandle($phid)

parameterswild$phid
returnPhabricatorObjectHandleHandle to the object.

Get the handle for an object PHID. You must overload getRequiredHandlePHIDs() (or a more specific version thereof) and include the PHID you want in the list for it to be available here.

public getKeyForConduit()

returnwild
This method is not documented.

public getKeyForSearchIndex()

returnwild
NOTE: Keys *must be* 4 characters for PhabricatorSearchEngineMySQL.

final protected getLoadedHandles()

returnwild
This method is not documented.

final protected getManualDiff()

returnwild
This method is not documented.

protected list getRequiredHandlePHIDs()

returnlistList of PHIDs to load handles for.

Specify which PhabricatorObjectHandles need to be loaded for your field to render correctly.

This is a convenience method which makes the handles available on all interfaces where the field appears. If your field needs handles on only some interfaces (or needs different handles on different interfaces) you can overload the more specific methods to customize which interfaces you retrieve handles for. Requesting only the handles you need will improve the performance of your field.

You can later retrieve these handles by calling getHandle().

public list getRequiredHandlePHIDsForCommitMessage()

returnlistList of PHIDs to load handles for.

Specify which PhabricatorObjectHandles need to be loaded for your field to render correctly on the commit message interface.

This is a more specific version of getRequiredHandlePHIDs() which can be overridden to improve field performance by loading only data you need.

public list getRequiredHandlePHIDsForRevisionEdit()

returnlistList of PHIDs to load handles for.

Specify which PhabricatorObjectHandles need to be loaded for your field to render correctly on the edit interface.

This is a more specific version of getRequiredHandlePHIDs() which can be overridden to improve field performance by loading only data you need.

public list getRequiredHandlePHIDsForRevisionList(DifferentialRevision $revision)

parametersDifferentialRevision$revisionThe revision to pull PHIDs for.
returnlistList of PHIDs to load handles for.

Specify which PhabricatorObjectHandles need to be loaded for your field to render correctly on the list interface.

This is a more specific version of getRequiredHandlePHIDs() which can be overridden to improve field performance by loading only data you need.

public list getRequiredHandlePHIDsForRevisionView()

returnlistList of PHIDs to load handles for.

Specify which PhabricatorObjectHandles need to be loaded for your field to render correctly on the view interface.

This is a more specific version of getRequiredHandlePHIDs() which can be overridden to improve field performance by loading only data you need.

final protected getRevision()

returnwild
This method is not documented.

public string|null getStorageKey()

returnstring|nullUnique key which identifies this field in auxiliary field storage. Maximum length is 32. Alternatively, null (default) to indicate that this field does not use auxiliary field storage.

Return a unique string used to key storage of this field's value, like "mycompany.fieldname" or similar. You can return null (the default) to indicate that this field does not use any storage. This is appropriate for display fields, like DifferentialLinesFieldSpecification. If you implement this, you must also implement getValueForStorage() and setValueFromStorage().

public list getSupportedCommitMessageLabels()

returnlistList of supported labels that this field can parse from commit messages.

Return one or more labels which this field parses in commit messages. For example, you might parse all of "Task", "Tasks" and "Task Numbers" or similar. This is just to make it easier to get commit messages to parse when users are typing in the fields manually as opposed to using a template, by accepting alternate spellings / pluralizations / etc. By default, only the label returned from renderLabelForCommitMessage() is parsed.

final protected getUser()

returnwild
This method is not documented.

public getValueForConduit()

returnwild
This method is not documented.

public getValueForSearchIndex()

returnwild
This method is not documented.

public string getValueForStorage()

returnstringSerialized field value.

Return a serialized representation of the field value, appropriate for storing in auxiliary field storage. You must implement this method if you implement getStorageKey().

final protected hasRevision()

returnwild

Determine if revision context is currently available.

protected list parseCommitMessageMailableList($value)

parametersstring$valueRaw list of comma-separated mailable names.
returnlistList of corresponding PHIDs.

Parse a list of mailable objects into a canonical PHID list.

public static list parseCommitMessageObjectList($value, $include_mailables, $allow_partial = false)

parametersstring$valueRaw list of comma-separated object names.
bool$include_mailablesTrue to include mailing lists.
bool$allow_partialTrue to make a best effort. By default, an exception is thrown if any item is invalid.
returnlistList of corresponding PHIDs.

Parse and lookup a list of object names, converting them to PHIDs.

protected list parseCommitMessageUserList($value)

parametersstring$valueRaw list of comma-separated user names.
returnlistList of corresponding PHIDs.

Parse a list of users into a canonical PHID list.

public mixed parseValueFromCommitMessage($value)

parametersstring$value
returnmixedThe canonical representation of the field value. For example, you should lookup usernames and object references.

Parse a raw text block from a commit message into a canonical representation of the field value. For example, the "CC" field accepts a comma-delimited list of usernames and emails and parses them into valid PHIDs, emitting a PHID list.

If you encounter errors (like a nonexistent username) while parsing, you should throw a DifferentialFieldParseException.

Generally, this method should accept whatever you return from renderValueForCommitMessage() and parse it back into a sensible representation.

You must implement this method if you return true from shouldAppearOnCommitMessage().

public AphrontView|string renderEditControl()

returnAphrontView|stringSomething renderable.

Build a renderable object (generally, some AphrontFormControl) which can be appended to a AphrontFormView and represents the interface the user sees on the "Edit Revision" screen when interacting with this field.

For example:

return id(new AphrontFormTextControl())
  ->setLabel('Custom Field')
  ->setName('my-custom-key')
  ->setValue($this->value);

You must implement this if you implement shouldAppearOnEdit().

public string renderHeaderForRevisionList()

returnstringColumn header.

Return a column header for revision list tables.

public string renderLabelForCommitMessage()

returnstringHuman-readable field label for commit messages.

Render a human-readable label for this field, like "Summary" or "Test Plan". This is distinct from the commit message key, but generally they should be similar.

public string renderLabelForDiffView()

returnstringLabel for field in revision detail view.

Return a string field label which will appear in the diff detail table.

You must implement this method if you return true from shouldAppearOnDiffView().

public string renderLabelForRevisionView()

returnstringLabel for field in revision detail view.

Return a string field label which will appear in the revision detail table.

You must implement this method if you return true from shouldAppearOnRevisionView().

public string renderUserList(array $user_phids)

parametersarray$user_phids
returnstringDisplay markup.

Load users, their current statuses and return a markup with links to the user profiles and information about their current status.

public string renderValueForCommitMessage($is_edit)

parametersbool$is_editTrue if the message is being edited.
returnstringHuman-readable field value.

Render a human-readable value for this field when it appears in commit messages (for instance, lists of users should be rendered as user names).

The $is_edit parameter allows you to distinguish between commit messages being rendered for editing and those being rendered for amending or commit. Some fields may decline to render a value in one mode (for example, "Reviewed By" appears only when doing commit/amend, not while editing).

public string|null renderValueForDiffView()

returnstring|nullDisplay markup for field value, or null to suppress field rendering.

Return a markup block representing the field for the diff detail view. Note that you can return null to suppress display (for instance, if the field shows related objects of some type and the revision doesn't have any related objects).

You must implement this method if you return true from shouldAppearOnDiffView().

public int renderValueForMail($phase)

parameterswild$phase
returnintOne of DifferentialMailPhase constants. string|null Plain text, or null for no message.

Return plain text to render in e-mail messages. The text may span multiple lines.

public string renderValueForRevisionList(DifferentialRevision $revision)

parametersDifferentialRevision$revisionThe revision to render a value for.
returnstringTable cell value.

Return a table cell value for revision list tables.

public string|null renderValueForRevisionView()

returnstring|nullDisplay markup for field value, or null to suppress field rendering.

Return a markup block representing the field for the revision detail view. Note that you can return null to suppress display (for instance, if the field shows related objects of some type and the revision doesn't have any related objects).

You must implement this method if you return true from shouldAppearOnRevisionView().

public string|null renderWarningBoxForRevisionAccept()

returnstring|nullDisplay markup for warning box, or null for no warning

Return a markup block representing a warning to display with the comment box when preparing to accept a diff. A return value of null indicates no warning box should be displayed for this field.

final public setDiff(DifferentialDiff $diff)

parametersDifferentialDiff$diff
returnwild
This method is not documented.

final public setDiffProperties(array $diff_properties)

parametersarray$diff_properties
returnwild
This method is not documented.

final public setHandles(array $handles)

parametersarray$handles
returnwild
This method is not documented.

final public setManualDiff(DifferentialDiff $diff)

parametersDifferentialDiff$diff
returnwild
This method is not documented.

final public setRevision(DifferentialRevision $revision)

parametersDifferentialRevision$revision
returnwild
This method is not documented.

final public setUser(PhabricatorUser $user)

parametersPhabricatorUser$user
returnwild
This method is not documented.

public this setValueFromParsedCommitMessage($value)

parametersmixed$valueField value from a parsed commit message dictionary.
returnthis

Set this field's value from a value in a parsed commit message dictionary. Afterward, this field will go through the normal write workflows and the change will be permanently stored via either the storage mechanisms (if your field implements them), revision write hooks (if your field implements them) or discarded (if your field implements neither, e.g. is just a display field).

The value you receive will either be null or something you originally returned from parseValueFromCommitMessage().

You must implement this method if you return true from shouldAppearOnCommitMessage().

public this setValueFromRequest(AphrontRequest $request)

parametersAphrontRequest$requestHTTP request representing a user submitting a form with this field in it.
returnthis

Set the field's value from an HTTP request. Generally, you should read the value of some field name you emitted in renderEditControl() and save it into the object, e.g.:

$this->value = $request->getStr('my-custom-field');

If you have some particularly complicated field, you may need to read more data; this is why you have access to the entire request.

You must implement this if you implement shouldAppearOnEdit().

You should not perform field validation here; instead, you should implement validateField().

public this setValueFromStorage($value)

parametersstring|null$valueSerialized field representation (from getValueForStorage()) or null if no value has ever been stored.
returnthis

Set the field's value given a serialized storage value. This is called when the field is loaded; if no data is available, the value will be null. You must implement this method if you implement getStorageKey().

public shouldAddToSearchIndex()

returnwild
This method is not documented.

public bool shouldAppearOnCommitMessage()

returnboolTrue if this field appears in commit messages in any capacity.

Determine if this field should appear in commit messages. You should return true if this field participates in any part of the commit message workflow, even if it is not rendered by default.

If you implement this method, you must implement getCommitMessageKey() and setValueFromParsedCommitMessage().

public bool shouldAppearOnCommitMessageTemplate()

returnboolTrue to indicate the field should appear in the edit template.

Return true if this field should be suggested to the user during "arc diff --edit". Basicially, return true if the field is something the user might want to fill out (like "Summary"), and false if it's a system/display/readonly field (like "Differential Revision"). If this method returns true, the field will be rendered even if it has no value during edit and update operations.

public shouldAppearOnConduitView()

returnwild
This method is not documented.

public bool shouldAppearOnDiffView()

returnboolTrue if this field should appear when viewing a diff.

Determine if this field should appear on the diff detail view interface. One use of this interface is to add purely informational fields to the diff view, without any sort of backing storage.

NOTE: These diffs are not necessarily attached yet to a revision. As such, a field on the diff view can not rely on the existence of a revision or use storage attached to the revision.

If you return true from this method, you must implement the methods renderLabelForDiffView() and renderValueForDiffView().

public bool shouldAppearOnEdit()

returnboolTrue to indicate that this field implements an edit interface.

Determine if this field should appear on the "Edit Revision" interface. If you return true from this method, you must implement setValueFromRequest(), renderEditControl() and validateField().

For a concrete example of a field which implements an edit interface, see DifferentialRevertPlanFieldSpecification.

public bool shouldAppearOnRevisionList()

returnboolTrue if this field should appear in the table.

Determine if this field should appear in the table on the revision list interface.

public bool shouldAppearOnRevisionView()

returnboolTrue if this field should appear when viewing a revision.

Determine if this field should appear on the revision detail view interface. One use of this interface is to add purely informational fields to the revision view, without any sort of backing storage.

If you return true from this method, you must implement the methods renderLabelForRevisionView() and renderValueForRevisionView().

public bool shouldExtractMentions()

returnbool

Determine if user mentions should be extracted from the value and added to CC when creating revision. Mentions are then extracted from the string returned by renderValueForCommitMessage().

By default, mentions are not extracted.

public bool shouldOverwriteWhenCommitMessageIsEdited()

returnboolTrue to indicate the field is save to overwrite.

In revision control systems which read revision information from the working copy, the user may edit the commit message outside of invoking "arc diff --edit". When they do this, only some fields (those fields which can not be edited by other users) are safe to overwrite. For instance, it is fine to overwrite "Summary" because no one else can edit it, but not to overwrite "Reviewers" because reviewers may have been added or removed via the web interface.

If a field is safe to overwrite when edited in a working copy commit message, return true. If the authoritative value should always be used, return false. By default, fields can not be overwritten.

arc will only attempt to overwrite field values if run with "--verbatim".

public void validateField()

returnvoid

This method will be called after setValueFromRequest() but before the field is saved. It gives you an opportunity to inspect the field value and throw a DifferentialFieldValidationException if there is a problem with the value the user has provided (for example, the value the user entered is not correctly formatted). This method is also called after setValueFromParsedCommitMessage() before the revision is saved.

By default, fields are not validated.

public void willWriteRevision(DifferentialRevisionEditor $editor)

parametersDifferentialRevisionEditor$editorActive editor which is applying changes to the revision.
returnvoid

Hook for applying revision changes via the editor. Normally, you should not implement this, but a number of builtin fields use the revision object itself as storage. If you need to do something similar for whatever reason, this method gives you an opportunity to interact with the editor or revision before changes are saved (for example, you can write the field's value into some property of the revision).