1
0
Fork 0
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:
epriestley 2015-04-18 08:38:47 -07:00
parent e27c0b416d
commit a11dab59b0
4 changed files with 40 additions and 43 deletions

View file

@ -67,6 +67,9 @@ final class DifferentialAddCommentView extends AphrontView {
'resign' => pht('Suggest Reviewers'), 'resign' => pht('Suggest Reviewers'),
); );
$mailable_source = new PhabricatorMetaMTAMailableDatasource();
$reviewer_source = new PhabricatorProjectOrUserDatasource();
$form = new AphrontFormView(); $form = new AphrontFormView();
$form $form
->setWorkflow(true) ->setWorkflow(true)
@ -88,7 +91,8 @@ final class DifferentialAddCommentView extends AphrontView {
->setControlID('add-reviewers') ->setControlID('add-reviewers')
->setControlStyle($enable_reviewers ? null : 'display: none') ->setControlStyle($enable_reviewers ? null : 'display: none')
->setID('add-reviewers-tokenizer') ->setID('add-reviewers-tokenizer')
->setDisableBehavior(true)) ->setDisableBehavior(true)
->setDatasource($reviewer_source))
->appendControl( ->appendControl(
id(new AphrontFormTokenizerControl()) id(new AphrontFormTokenizerControl())
->setLabel(pht('Add Subscribers')) ->setLabel(pht('Add Subscribers'))
@ -96,7 +100,8 @@ final class DifferentialAddCommentView extends AphrontView {
->setControlID('add-ccs') ->setControlID('add-ccs')
->setControlStyle($enable_ccs ? null : 'display: none') ->setControlStyle($enable_ccs ? null : 'display: none')
->setID('add-ccs-tokenizer') ->setID('add-ccs-tokenizer')
->setDisableBehavior(true)) ->setDisableBehavior(true)
->setDatasource($mailable_source))
->appendChild( ->appendChild(
id(new PhabricatorRemarkupControl()) id(new PhabricatorRemarkupControl())
->setName('comment') ->setName('comment')
@ -108,9 +113,6 @@ final class DifferentialAddCommentView extends AphrontView {
id(new AphrontFormSubmitControl()) id(new AphrontFormSubmitControl())
->setValue(pht('Submit'))); ->setValue(pht('Submit')));
$mailable_source = new PhabricatorMetaMTAMailableDatasource();
$reviewer_source = new PhabricatorProjectOrUserDatasource();
Javelin::initBehavior( Javelin::initBehavior(
'differential-add-reviewers-and-ccs', 'differential-add-reviewers-and-ccs',
array( array(

View file

@ -677,6 +677,9 @@ final class DiffusionCommitController extends DiffusionController {
$actions = $this->getAuditActions($commit, $audit_requests); $actions = $this->getAuditActions($commit, $audit_requests);
$mailable_source = new PhabricatorMetaMTAMailableDatasource();
$auditor_source = new DiffusionAuditorDatasource();
$form = id(new AphrontFormView()) $form = id(new AphrontFormView())
->setUser($user) ->setUser($user)
->setAction('/audit/addcomment/') ->setAction('/audit/addcomment/')
@ -694,7 +697,8 @@ final class DiffusionCommitController extends DiffusionController {
->setControlID('add-auditors') ->setControlID('add-auditors')
->setControlStyle('display: none') ->setControlStyle('display: none')
->setID('add-auditors-tokenizer') ->setID('add-auditors-tokenizer')
->setDisableBehavior(true)) ->setDisableBehavior(true)
->setDatasource($auditor_source))
->appendControl( ->appendControl(
id(new AphrontFormTokenizerControl()) id(new AphrontFormTokenizerControl())
->setLabel(pht('Add CCs')) ->setLabel(pht('Add CCs'))
@ -702,7 +706,8 @@ final class DiffusionCommitController extends DiffusionController {
->setControlID('add-ccs') ->setControlID('add-ccs')
->setControlStyle('display: none') ->setControlStyle('display: none')
->setID('add-ccs-tokenizer') ->setID('add-ccs-tokenizer')
->setDisableBehavior(true)) ->setDisableBehavior(true)
->setDatasource($mailable_source))
->appendChild( ->appendChild(
id(new PhabricatorRemarkupControl()) id(new PhabricatorRemarkupControl())
->setLabel(pht('Comments')) ->setLabel(pht('Comments'))
@ -718,9 +723,6 @@ final class DiffusionCommitController extends DiffusionController {
$header->setHeader( $header->setHeader(
$is_serious ? pht('Audit Commit') : pht('Creative Accounting')); $is_serious ? pht('Audit Commit') : pht('Creative Accounting'));
$mailable_source = new PhabricatorMetaMTAMailableDatasource();
$auditor_source = new DiffusionAuditorDatasource();
Javelin::initBehavior( Javelin::initBehavior(
'differential-add-reviewers-and-ccs', 'differential-add-reviewers-and-ccs',
array( array(

View file

@ -182,6 +182,10 @@ final class ManiphestTaskDetailController extends ManiphestController {
$draft_text = null; $draft_text = null;
} }
$projects_source = new PhabricatorProjectDatasource();
$users_source = new PhabricatorPeopleDatasource();
$mailable_source = new PhabricatorMetaMTAMailableDatasource();
$comment_form = new AphrontFormView(); $comment_form = new AphrontFormView();
$comment_form $comment_form
->setUser($user) ->setUser($user)
@ -209,7 +213,8 @@ final class ManiphestTaskDetailController extends ManiphestController {
->setControlID('assign_to') ->setControlID('assign_to')
->setControlStyle('display: none') ->setControlStyle('display: none')
->setID('assign-tokenizer') ->setID('assign-tokenizer')
->setDisableBehavior(true)) ->setDisableBehavior(true)
->setDatasource($users_source))
->appendControl( ->appendControl(
id(new AphrontFormTokenizerControl()) id(new AphrontFormTokenizerControl())
->setLabel(pht('CCs')) ->setLabel(pht('CCs'))
@ -217,7 +222,8 @@ final class ManiphestTaskDetailController extends ManiphestController {
->setControlID('ccs') ->setControlID('ccs')
->setControlStyle('display: none') ->setControlStyle('display: none')
->setID('cc-tokenizer') ->setID('cc-tokenizer')
->setDisableBehavior(true)) ->setDisableBehavior(true)
->setDatasource($mailable_source))
->appendChild( ->appendChild(
id(new AphrontFormSelectControl()) id(new AphrontFormSelectControl())
->setLabel(pht('Priority')) ->setLabel(pht('Priority'))
@ -233,7 +239,8 @@ final class ManiphestTaskDetailController extends ManiphestController {
->setControlID('projects') ->setControlID('projects')
->setControlStyle('display: none') ->setControlStyle('display: none')
->setID('projects-tokenizer') ->setID('projects-tokenizer')
->setDisableBehavior(true)) ->setDisableBehavior(true)
->setDatasource($projects_source))
->appendChild( ->appendChild(
id(new AphrontFormFileControl()) id(new AphrontFormFileControl())
->setLabel(pht('File')) ->setLabel(pht('File'))
@ -260,10 +267,6 @@ final class ManiphestTaskDetailController extends ManiphestController {
PhabricatorTransactions::TYPE_EDGE => 'projects', PhabricatorTransactions::TYPE_EDGE => 'projects',
); );
$projects_source = new PhabricatorProjectDatasource();
$users_source = new PhabricatorPeopleDatasource();
$mailable_source = new PhabricatorMetaMTAMailableDatasource();
$tokenizer_map = array( $tokenizer_map = array(
PhabricatorTransactions::TYPE_EDGE => array( PhabricatorTransactions::TYPE_EDGE => array(
'id' => 'projects-tokenizer', 'id' => 'projects-tokenizer',

View file

@ -51,18 +51,16 @@ final class AphrontFormTokenizerControl extends AphrontFormControl {
} }
$datasource = $this->datasource; $datasource = $this->datasource;
if ($datasource) { if (!$datasource) {
$datasource->setViewer($this->getUser()); throw new Exception(
pht('You must set a datasource to use a TokenizerControl.'));
} }
$datasource->setViewer($this->getUser());
$placeholder = null; $placeholder = null;
if (!strlen($this->placeholder)) { if (!strlen($this->placeholder)) {
if ($datasource) {
$placeholder = $datasource->getPlaceholderText(); $placeholder = $datasource->getPlaceholderText();
} }
} else {
$placeholder = $this->placeholder;
}
$tokens = array(); $tokens = array();
$values = nonempty($this->getValue(), array()); $values = nonempty($this->getValue(), array());
@ -71,7 +69,7 @@ final class AphrontFormTokenizerControl extends AphrontFormControl {
$token = PhabricatorTypeaheadTokenView::newFromHandle($handles[$value]); $token = PhabricatorTypeaheadTokenView::newFromHandle($handles[$value]);
} else { } else {
$token = null; $token = null;
if ($datasource) {
$function = $datasource->parseFunction($value); $function = $datasource->parseFunction($value);
if ($function) { if ($function) {
$token_list = $datasource->renderFunctionTokens( $token_list = $datasource->renderFunctionTokens(
@ -79,7 +77,6 @@ final class AphrontFormTokenizerControl extends AphrontFormControl {
array($function['argv'])); array($function['argv']));
$token = head($token_list); $token = head($token_list);
} }
}
if (!$token) { if (!$token) {
$name = pht('Invalid Function: %s', $value); $name = pht('Invalid Function: %s', $value);
@ -105,18 +102,11 @@ final class AphrontFormTokenizerControl extends AphrontFormControl {
$username = $this->user->getUsername(); $username = $this->user->getUsername();
} }
$datasource_uri = null;
$browse_uri = null;
if ($datasource) {
$datasource->setViewer($this->getUser());
$datasource_uri = $datasource->getDatasourceURI(); $datasource_uri = $datasource->getDatasourceURI();
$browse_uri = $datasource->getBrowseURI(); $browse_uri = $datasource->getBrowseURI();
if ($browse_uri) { if ($browse_uri) {
$template->setBrowseURI($browse_uri); $template->setBrowseURI($browse_uri);
} }
}
if (!$this->disableBehavior) { if (!$this->disableBehavior) {
Javelin::initBehavior('aphront-basic-tokenizer', array( Javelin::initBehavior('aphront-basic-tokenizer', array(