mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-19 05:12:41 +01:00
Require TokenizerControl to always have a datasource
Summary: Ref T4100. I can simplify the logic a bit here by moving some rendering into the datasources, but a few TokenizerControls currently don't have datasources. Require datasources and always provide datasources. Test Plan: - Used previously-datasourceless controls (e.g., "Add Reviewers"). - Used normal controls. - Manually verified that no other controls are missing datasources. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T4100 Differential Revision: https://secure.phabricator.com/D12456
This commit is contained in:
parent
e27c0b416d
commit
a11dab59b0
4 changed files with 40 additions and 43 deletions
|
@ -67,6 +67,9 @@ final class DifferentialAddCommentView extends AphrontView {
|
|||
'resign' => pht('Suggest Reviewers'),
|
||||
);
|
||||
|
||||
$mailable_source = new PhabricatorMetaMTAMailableDatasource();
|
||||
$reviewer_source = new PhabricatorProjectOrUserDatasource();
|
||||
|
||||
$form = new AphrontFormView();
|
||||
$form
|
||||
->setWorkflow(true)
|
||||
|
@ -88,7 +91,8 @@ final class DifferentialAddCommentView extends AphrontView {
|
|||
->setControlID('add-reviewers')
|
||||
->setControlStyle($enable_reviewers ? null : 'display: none')
|
||||
->setID('add-reviewers-tokenizer')
|
||||
->setDisableBehavior(true))
|
||||
->setDisableBehavior(true)
|
||||
->setDatasource($reviewer_source))
|
||||
->appendControl(
|
||||
id(new AphrontFormTokenizerControl())
|
||||
->setLabel(pht('Add Subscribers'))
|
||||
|
@ -96,7 +100,8 @@ final class DifferentialAddCommentView extends AphrontView {
|
|||
->setControlID('add-ccs')
|
||||
->setControlStyle($enable_ccs ? null : 'display: none')
|
||||
->setID('add-ccs-tokenizer')
|
||||
->setDisableBehavior(true))
|
||||
->setDisableBehavior(true)
|
||||
->setDatasource($mailable_source))
|
||||
->appendChild(
|
||||
id(new PhabricatorRemarkupControl())
|
||||
->setName('comment')
|
||||
|
@ -108,9 +113,6 @@ final class DifferentialAddCommentView extends AphrontView {
|
|||
id(new AphrontFormSubmitControl())
|
||||
->setValue(pht('Submit')));
|
||||
|
||||
$mailable_source = new PhabricatorMetaMTAMailableDatasource();
|
||||
$reviewer_source = new PhabricatorProjectOrUserDatasource();
|
||||
|
||||
Javelin::initBehavior(
|
||||
'differential-add-reviewers-and-ccs',
|
||||
array(
|
||||
|
|
|
@ -677,6 +677,9 @@ final class DiffusionCommitController extends DiffusionController {
|
|||
|
||||
$actions = $this->getAuditActions($commit, $audit_requests);
|
||||
|
||||
$mailable_source = new PhabricatorMetaMTAMailableDatasource();
|
||||
$auditor_source = new DiffusionAuditorDatasource();
|
||||
|
||||
$form = id(new AphrontFormView())
|
||||
->setUser($user)
|
||||
->setAction('/audit/addcomment/')
|
||||
|
@ -694,7 +697,8 @@ final class DiffusionCommitController extends DiffusionController {
|
|||
->setControlID('add-auditors')
|
||||
->setControlStyle('display: none')
|
||||
->setID('add-auditors-tokenizer')
|
||||
->setDisableBehavior(true))
|
||||
->setDisableBehavior(true)
|
||||
->setDatasource($auditor_source))
|
||||
->appendControl(
|
||||
id(new AphrontFormTokenizerControl())
|
||||
->setLabel(pht('Add CCs'))
|
||||
|
@ -702,7 +706,8 @@ final class DiffusionCommitController extends DiffusionController {
|
|||
->setControlID('add-ccs')
|
||||
->setControlStyle('display: none')
|
||||
->setID('add-ccs-tokenizer')
|
||||
->setDisableBehavior(true))
|
||||
->setDisableBehavior(true)
|
||||
->setDatasource($mailable_source))
|
||||
->appendChild(
|
||||
id(new PhabricatorRemarkupControl())
|
||||
->setLabel(pht('Comments'))
|
||||
|
@ -718,9 +723,6 @@ final class DiffusionCommitController extends DiffusionController {
|
|||
$header->setHeader(
|
||||
$is_serious ? pht('Audit Commit') : pht('Creative Accounting'));
|
||||
|
||||
$mailable_source = new PhabricatorMetaMTAMailableDatasource();
|
||||
$auditor_source = new DiffusionAuditorDatasource();
|
||||
|
||||
Javelin::initBehavior(
|
||||
'differential-add-reviewers-and-ccs',
|
||||
array(
|
||||
|
|
|
@ -182,6 +182,10 @@ final class ManiphestTaskDetailController extends ManiphestController {
|
|||
$draft_text = null;
|
||||
}
|
||||
|
||||
$projects_source = new PhabricatorProjectDatasource();
|
||||
$users_source = new PhabricatorPeopleDatasource();
|
||||
$mailable_source = new PhabricatorMetaMTAMailableDatasource();
|
||||
|
||||
$comment_form = new AphrontFormView();
|
||||
$comment_form
|
||||
->setUser($user)
|
||||
|
@ -209,7 +213,8 @@ final class ManiphestTaskDetailController extends ManiphestController {
|
|||
->setControlID('assign_to')
|
||||
->setControlStyle('display: none')
|
||||
->setID('assign-tokenizer')
|
||||
->setDisableBehavior(true))
|
||||
->setDisableBehavior(true)
|
||||
->setDatasource($users_source))
|
||||
->appendControl(
|
||||
id(new AphrontFormTokenizerControl())
|
||||
->setLabel(pht('CCs'))
|
||||
|
@ -217,7 +222,8 @@ final class ManiphestTaskDetailController extends ManiphestController {
|
|||
->setControlID('ccs')
|
||||
->setControlStyle('display: none')
|
||||
->setID('cc-tokenizer')
|
||||
->setDisableBehavior(true))
|
||||
->setDisableBehavior(true)
|
||||
->setDatasource($mailable_source))
|
||||
->appendChild(
|
||||
id(new AphrontFormSelectControl())
|
||||
->setLabel(pht('Priority'))
|
||||
|
@ -233,7 +239,8 @@ final class ManiphestTaskDetailController extends ManiphestController {
|
|||
->setControlID('projects')
|
||||
->setControlStyle('display: none')
|
||||
->setID('projects-tokenizer')
|
||||
->setDisableBehavior(true))
|
||||
->setDisableBehavior(true)
|
||||
->setDatasource($projects_source))
|
||||
->appendChild(
|
||||
id(new AphrontFormFileControl())
|
||||
->setLabel(pht('File'))
|
||||
|
@ -260,10 +267,6 @@ final class ManiphestTaskDetailController extends ManiphestController {
|
|||
PhabricatorTransactions::TYPE_EDGE => 'projects',
|
||||
);
|
||||
|
||||
$projects_source = new PhabricatorProjectDatasource();
|
||||
$users_source = new PhabricatorPeopleDatasource();
|
||||
$mailable_source = new PhabricatorMetaMTAMailableDatasource();
|
||||
|
||||
$tokenizer_map = array(
|
||||
PhabricatorTransactions::TYPE_EDGE => array(
|
||||
'id' => 'projects-tokenizer',
|
||||
|
|
|
@ -51,18 +51,16 @@ final class AphrontFormTokenizerControl extends AphrontFormControl {
|
|||
}
|
||||
|
||||
$datasource = $this->datasource;
|
||||
if ($datasource) {
|
||||
$datasource->setViewer($this->getUser());
|
||||
if (!$datasource) {
|
||||
throw new Exception(
|
||||
pht('You must set a datasource to use a TokenizerControl.'));
|
||||
}
|
||||
$datasource->setViewer($this->getUser());
|
||||
|
||||
$placeholder = null;
|
||||
if (!strlen($this->placeholder)) {
|
||||
if ($datasource) {
|
||||
$placeholder = $datasource->getPlaceholderText();
|
||||
}
|
||||
} else {
|
||||
$placeholder = $this->placeholder;
|
||||
}
|
||||
|
||||
$tokens = array();
|
||||
$values = nonempty($this->getValue(), array());
|
||||
|
@ -71,7 +69,7 @@ final class AphrontFormTokenizerControl extends AphrontFormControl {
|
|||
$token = PhabricatorTypeaheadTokenView::newFromHandle($handles[$value]);
|
||||
} else {
|
||||
$token = null;
|
||||
if ($datasource) {
|
||||
|
||||
$function = $datasource->parseFunction($value);
|
||||
if ($function) {
|
||||
$token_list = $datasource->renderFunctionTokens(
|
||||
|
@ -79,7 +77,6 @@ final class AphrontFormTokenizerControl extends AphrontFormControl {
|
|||
array($function['argv']));
|
||||
$token = head($token_list);
|
||||
}
|
||||
}
|
||||
|
||||
if (!$token) {
|
||||
$name = pht('Invalid Function: %s', $value);
|
||||
|
@ -105,18 +102,11 @@ final class AphrontFormTokenizerControl extends AphrontFormControl {
|
|||
$username = $this->user->getUsername();
|
||||
}
|
||||
|
||||
$datasource_uri = null;
|
||||
$browse_uri = null;
|
||||
if ($datasource) {
|
||||
$datasource->setViewer($this->getUser());
|
||||
|
||||
$datasource_uri = $datasource->getDatasourceURI();
|
||||
|
||||
$browse_uri = $datasource->getBrowseURI();
|
||||
if ($browse_uri) {
|
||||
$template->setBrowseURI($browse_uri);
|
||||
}
|
||||
}
|
||||
|
||||
if (!$this->disableBehavior) {
|
||||
Javelin::initBehavior('aphront-basic-tokenizer', array(
|
||||
|
|
Loading…
Reference in a new issue