mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-30 18:52:42 +01:00
33ec855449
Summary: Ref T9789. `Transaction` and `Editor` classes are the last major pieces of infrastructure that haven't been fully modularized. Some of the specific issues are: - `Editor` classes rely on a bunch of `instanceof` stuff in the base class to pick up transaction types like "subscribe", "projects", etc. Instead, applications should be adding these, and third-party applications should be able to add them. - Code is spread across `Transaction` and `Editor` classes somewhat oddly. For example, generating old/new values would probably make more sense at the `Transaction` level, but it currently exists at the `Editor` level. - Both types of classes have a lot of functions based on `switch()` statements, which require a ton of boilerplate and are just generally kind of hard to work with. This creates classes for each type of transaction, and moves almost all of the logic to them. These classes are simpler and more focused than the old stuff was, and can organize related code better. This starts inching toward defining `CoreTransactions` for features shared across applications. It only defines the "Create" transaction so far, but at some point I plan to move all the other shared transactions to Core and let them control which objects they're available for. Test Plan: - Created pastes with web UI and API. - Edited all paste properites. - Archived/activated. - Verified files got reasonable names. - Reviewed timeline and feed. Reviewers: chad Reviewed By: chad Maniphest Tasks: T9789 Differential Revision: https://secure.phabricator.com/D16111
120 lines
3.7 KiB
PHP
120 lines
3.7 KiB
PHP
<?php
|
|
|
|
final class PhabricatorPasteEditEngine
|
|
extends PhabricatorEditEngine {
|
|
|
|
const ENGINECONST = 'paste.paste';
|
|
|
|
public function getEngineName() {
|
|
return pht('Pastes');
|
|
}
|
|
|
|
public function getSummaryHeader() {
|
|
return pht('Configure Paste Forms');
|
|
}
|
|
|
|
public function getSummaryText() {
|
|
return pht('Configure creation and editing forms in Paste.');
|
|
}
|
|
|
|
public function getEngineApplicationClass() {
|
|
return 'PhabricatorPasteApplication';
|
|
}
|
|
|
|
protected function newEditableObject() {
|
|
return PhabricatorPaste::initializeNewPaste($this->getViewer());
|
|
}
|
|
|
|
protected function newObjectQuery() {
|
|
return id(new PhabricatorPasteQuery())
|
|
->needRawContent(true);
|
|
}
|
|
|
|
protected function getObjectCreateTitleText($object) {
|
|
return pht('Create New Paste');
|
|
}
|
|
|
|
protected function getObjectEditTitleText($object) {
|
|
return pht('Edit Paste: %s', $object->getTitle());
|
|
}
|
|
|
|
protected function getObjectEditShortText($object) {
|
|
return $object->getMonogram();
|
|
}
|
|
|
|
protected function getObjectCreateShortText() {
|
|
return pht('Create Paste');
|
|
}
|
|
|
|
protected function getObjectName() {
|
|
return pht('Paste');
|
|
}
|
|
|
|
protected function getCommentViewHeaderText($object) {
|
|
return pht('Eat Paste');
|
|
}
|
|
|
|
protected function getCommentViewButtonText($object) {
|
|
return pht('Nom Nom Nom Nom Nom');
|
|
}
|
|
|
|
protected function getObjectViewURI($object) {
|
|
return '/P'.$object->getID();
|
|
}
|
|
|
|
protected function buildCustomEditFields($object) {
|
|
$langs = array(
|
|
'' => pht('(Detect From Filename in Title)'),
|
|
) + PhabricatorEnv::getEnvConfig('pygments.dropdown-choices');
|
|
|
|
return array(
|
|
id(new PhabricatorTextEditField())
|
|
->setKey('title')
|
|
->setLabel(pht('Title'))
|
|
->setTransactionType(PhabricatorPasteTitleTransaction::TRANSACTIONTYPE)
|
|
->setDescription(pht('The title of the paste.'))
|
|
->setConduitDescription(pht('Retitle the paste.'))
|
|
->setConduitTypeDescription(pht('New paste title.'))
|
|
->setValue($object->getTitle()),
|
|
id(new PhabricatorSelectEditField())
|
|
->setKey('language')
|
|
->setLabel(pht('Language'))
|
|
->setTransactionType(
|
|
PhabricatorPasteLanguageTransaction::TRANSACTIONTYPE)
|
|
->setAliases(array('lang'))
|
|
->setIsCopyable(true)
|
|
->setOptions($langs)
|
|
->setDescription(
|
|
pht(
|
|
'Language used for syntax highlighting. By default, inferred '.
|
|
'from the title.'))
|
|
->setConduitDescription(
|
|
pht('Change language used for syntax highlighting.'))
|
|
->setConduitTypeDescription(pht('New highlighting language.'))
|
|
->setValue($object->getLanguage()),
|
|
id(new PhabricatorTextAreaEditField())
|
|
->setKey('text')
|
|
->setLabel(pht('Text'))
|
|
->setTransactionType(
|
|
PhabricatorPasteContentTransaction::TRANSACTIONTYPE)
|
|
->setMonospaced(true)
|
|
->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_TALL)
|
|
->setDescription(pht('The main body text of the paste.'))
|
|
->setConduitDescription(pht('Change the paste content.'))
|
|
->setConduitTypeDescription(pht('New body content.'))
|
|
->setValue($object->getRawContent()),
|
|
id(new PhabricatorSelectEditField())
|
|
->setKey('status')
|
|
->setLabel(pht('Status'))
|
|
->setTransactionType(
|
|
PhabricatorPasteStatusTransaction::TRANSACTIONTYPE)
|
|
->setIsConduitOnly(true)
|
|
->setOptions(PhabricatorPaste::getStatusNameMap())
|
|
->setDescription(pht('Active or archived status.'))
|
|
->setConduitDescription(pht('Active or archive the paste.'))
|
|
->setConduitTypeDescription(pht('New paste status constant.'))
|
|
->setValue($object->getStatus()),
|
|
);
|
|
}
|
|
|
|
}
|