Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/macro/controller/PhabricatorMacroMemeDialogController.php
12241 views
1
<?php
2
3
final class PhabricatorMacroMemeDialogController
4
extends PhabricatorMacroController {
5
6
public function handleRequest(AphrontRequest $request) {
7
$viewer = $request->getViewer();
8
9
$phid = head($request->getArr('macro'));
10
$above = $request->getStr('above');
11
$below = $request->getStr('below');
12
13
$e_macro = true;
14
$errors = array();
15
if ($request->isDialogFormPost()) {
16
if (!$phid) {
17
$e_macro = pht('Required');
18
$errors[] = pht('Macro name is required.');
19
} else {
20
$macro = id(new PhabricatorMacroQuery())
21
->setViewer($viewer)
22
->withPHIDs(array($phid))
23
->executeOne();
24
if (!$macro) {
25
$e_macro = pht('Invalid');
26
$errors[] = pht('No such macro.');
27
}
28
}
29
30
if (!$errors) {
31
$options = new PhutilSimpleOptions();
32
$data = array(
33
'src' => $macro->getName(),
34
'above' => $above,
35
'below' => $below,
36
);
37
$string = $options->unparse($data, $escape = '}');
38
39
$result = array(
40
'text' => "{meme, {$string}}",
41
);
42
return id(new AphrontAjaxResponse())->setContent($result);
43
}
44
}
45
46
$view = id(new AphrontFormView())
47
->setUser($viewer)
48
->appendControl(
49
id(new AphrontFormTokenizerControl())
50
->setLabel(pht('Macro'))
51
->setName('macro')
52
->setLimit(1)
53
->setDatasource(new PhabricatorMacroDatasource())
54
->setError($e_macro))
55
->appendChild(
56
id(new AphrontFormTextControl())
57
->setLabel(pht('Above'))
58
->setName('above')
59
->setValue($above))
60
->appendChild(
61
id(new AphrontFormTextControl())
62
->setLabel(pht('Below'))
63
->setName('below')
64
->setValue($below));
65
66
$dialog = id(new AphrontDialogView())
67
->setUser($viewer)
68
->setTitle(pht('Create Meme'))
69
->appendForm($view)
70
->addCancelButton('/')
71
->addSubmitButton(pht('Llama Diorama'));
72
73
return id(new AphrontDialogResponse())->setDialog($dialog);
74
}
75
76
}
77
78