Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / transactions / editengine / PhabricatorEditEngineAPIMethod.php
blob2028f10d90c4939427e1b3d63d028ecf79dad118
1 <?php
3 abstract class PhabricatorEditEngineAPIMethod
4 extends ConduitAPIMethod {
6 abstract public function newEditEngine();
8 public function getApplication() {
9 $engine = $this->newEditEngine();
10 $class = $engine->getEngineApplicationClass();
11 return PhabricatorApplication::getByClass($class);
14 final protected function defineParamTypes() {
15 return array(
16 'transactions' => 'list<map<string, wild>>',
17 'objectIdentifier' => 'optional id|phid|string',
21 final protected function defineReturnType() {
22 return 'map<string, wild>';
25 final protected function execute(ConduitAPIRequest $request) {
26 $engine = $this->newEditEngine()
27 ->setViewer($request->getUser());
29 return $engine->buildConduitResponse($request);
32 final public function getMethodDescription() {
33 return pht(
34 'This is a standard **ApplicationEditor** method which allows you to '.
35 'create and modify objects by applying transactions. For documentation '.
36 'on these endpoints, see '.
37 '**[[ %s | Conduit API: Using Edit Endpoints ]]**.',
38 PhabricatorEnv::getDoclink('Conduit API: Using Edit Endpoints'));
41 final protected function newDocumentationPages(PhabricatorUser $viewer) {
42 $engine = $this->newEditEngine()
43 ->setViewer($viewer);
45 $types = $engine->getConduitEditTypes();
47 $out = array();
49 return $this->buildEditTypesDocumentationPages($viewer, $engine, $types);
52 private function buildEditTypesDocumentationPages(
53 PhabricatorUser $viewer,
54 PhabricatorEditEngine $engine,
55 array $types) {
57 $pages = array();
59 $summary_info = pht(
60 'This endpoint supports these types of transactions. See below for '.
61 'detailed information about each transaction type.');
63 $rows = array();
64 foreach ($types as $type) {
65 $rows[] = array(
66 $type->getEditType(),
67 $type->getConduitDescription(),
71 $summary_table = id(new AphrontTableView($rows))
72 ->setHeaders(
73 array(
74 pht('Key'),
75 pht('Description'),
77 ->setColumnClasses(
78 array(
79 'prewrap',
80 'wide',
81 ));
83 $title = pht('Transaction Summary');
84 $content = array(
85 $this->buildRemarkup($summary_info),
86 $summary_table,
89 $pages[] = $this->newDocumentationBoxPage($viewer, $title, $content)
90 ->setAnchor('types');
92 foreach ($types as $type) {
93 $section = array();
95 $section[] = $type->getConduitDescription();
97 $type_documentation = $type->getConduitDocumentation();
98 if (strlen($type_documentation)) {
99 $section[] = $type_documentation;
102 $section = implode("\n\n", $section);
104 $rows = array();
106 $rows[] = array(
107 'type',
108 'const',
109 $type->getEditType(),
112 $rows[] = array(
113 'value',
114 $type->getConduitType(),
115 $type->getConduitTypeDescription(),
118 $type_table = id(new AphrontTableView($rows))
119 ->setHeaders(
120 array(
121 pht('Key'),
122 pht('Type'),
123 pht('Description'),
125 ->setColumnClasses(
126 array(
127 'prewrap',
128 'prewrap',
129 'wide',
132 $title = $type->getEditType();
133 $content = array(
134 $this->buildRemarkup($section),
135 $type_table,
138 $pages[] = $this->newDocumentationBoxPage($viewer, $title, $content)
139 ->setAnchor($type->getEditType())
140 ->setIconIcon('fa-pencil');
143 return $pages;
147 private function buildRemarkup($remarkup) {
148 $viewer = $this->getViewer();
150 $view = new PHUIRemarkupView($viewer, $remarkup);
152 $view->setRemarkupOptions(
153 array(
154 PHUIRemarkupView::OPTION_PRESERVE_LINEBREAKS => false,
157 return id(new PHUIBoxView())
158 ->appendChild($view)
159 ->addPadding(PHUI::PADDING_LARGE);