Page MenuHomePhabricator

Provide an Editor extension point for transaction validation

Authored by epriestley on Jan 27 2019, 6:31 PM.



Depends on D20040. Ref T13242. See PHI1039. See PHI873. Two reasonable cases have arisen recently where extending validation rules would help solve problems.

We can do this in a pretty straightforward way with a standard extension pattern.

Test Plan

Used this extension to keep ducks away from projects:


final class NoDucksEditorExtension
  extends PhabricatorEditorExtension {

  const EXTENSIONKEY = 'no.ducks';

  public function getExtensionName() {
    return pht('No Ducks!');

  public function supportsObject(
    PhabricatorApplicationTransactionEditor $editor,
    PhabricatorApplicationTransactionInterface $object) {
    return ($object instanceof PhabricatorProject);

  public function validateTransactions($object, array $xactions) {
    $errors = array();

    $name_type = PhabricatorProjectNameTransaction::TRANSACTIONTYPE;

    $old_value = $object->getName();
    foreach ($xactions as $xaction) {
      if ($xaction->getTransactionType() !== $name_type) {

      $new_value = $xaction->getNewValue();
      if ($old_value === $new_value) {

      if (preg_match('/duck/i', $new_value)) {
        $errors[] = $this->newInvalidTransactionError(
          pht('Project names must not contain the substring "duck".'));

    return $errors;


Diff Detail

rP Phabricator
Automatic diff as part of commit; lint not applicable.
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

epriestley created this revision.Jan 27 2019, 6:31 PM
epriestley requested review of this revision.Jan 27 2019, 6:33 PM
epriestley updated this revision to Diff 47854.Jan 27 2019, 8:03 PM
  • Minor correctness changes.
amckinley accepted this revision.Jan 29 2019, 2:59 AM
This revision is now accepted and ready to land.Jan 29 2019, 2:59 AM
This revision was automatically updated to reflect the committed changes.