Remove all "FileHasObject" edge reads and writes
[phabricator.git] / src / applications / macro / controller / PhabricatorMacroMemeDialogController.php
blob5851cc5ad828c130778734b2e84a05b29a9a2d89
1 <?php
3 final class PhabricatorMacroMemeDialogController
4 extends PhabricatorMacroController {
6 public function handleRequest(AphrontRequest $request) {
7 $viewer = $request->getViewer();
9 $phid = head($request->getArr('macro'));
10 $above = $request->getStr('above');
11 $below = $request->getStr('below');
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.');
30 if (!$errors) {
31 $options = new PhutilSimpleOptions();
32 $data = array(
33 'src' => $macro->getName(),
34 'above' => $above,
35 'below' => $below,
37 $string = $options->unparse($data, $escape = '}');
39 $result = array(
40 'text' => "{meme, {$string}}",
42 return id(new AphrontAjaxResponse())->setContent($result);
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));
66 $dialog = id(new AphrontDialogView())
67 ->setUser($viewer)
68 ->setTitle(pht('Create Meme'))
69 ->appendForm($view)
70 ->addCancelButton('/')
71 ->addSubmitButton(pht('Llama Diorama'));
73 return id(new AphrontDialogResponse())->setDialog($dialog);