1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-27 01:02:42 +01:00

Allow standard fields to be required

Summary: Ref T418.

Test Plan: See screenshot.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T418

Differential Revision: https://secure.phabricator.com/D7030
This commit is contained in:
epriestley 2013-09-18 15:32:14 -07:00
parent 3f24232d2b
commit c5b80985df

View file

@ -12,6 +12,8 @@ abstract class PhabricatorStandardCustomField
private $strings;
private $caption;
private $fieldError;
private $required;
private $default;
abstract public function getFieldType();
@ -102,6 +104,10 @@ abstract class PhabricatorStandardCustomField
case 'caption':
$this->setCaption($value);
break;
case 'required':
$this->setRequired($value);
$this->setFieldError(true);
break;
case 'type':
// We set this earlier on.
break;
@ -124,6 +130,15 @@ abstract class PhabricatorStandardCustomField
return $this->fieldError;
}
public function setRequired($required) {
$this->required = $required;
return $this;
}
public function getRequired() {
return $this->required;
}
/* -( PhabricatorCustomField )--------------------------------------------- */
@ -252,7 +267,34 @@ abstract class PhabricatorStandardCustomField
$type,
$xactions);
if ($this->getRequired()) {
$value = null;
$transaction = null;
foreach ($xactions as $xaction) {
$value = $xaction->getNewValue();
if (!$this->isValueEmpty($value)) {
$transaction = $xaction;
break;
}
}
if ($this->isValueEmpty($value)) {
$errors[] = new PhabricatorApplicationTransactionValidationError(
$type,
pht('Required'),
pht('%s is required.', $this->getFieldName()),
$transaction);
$this->setFieldError(pht('Required'));
}
}
return $errors;
}
protected function isValueEmpty($value) {
if (is_array($value)) {
return empty($value);
}
return !strlen($value);
}
}