[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class PhabricatorMailingListsEditController 4 extends PhabricatorMailingListsController { 5 6 private $id; 7 8 public function willProcessRequest(array $data) { 9 $this->id = idx($data, 'id'); 10 } 11 12 public function processRequest() { 13 $request = $this->getRequest(); 14 $viewer = $request->getUser(); 15 16 if ($this->id) { 17 $page_title = pht('Edit Mailing List'); 18 $list = id(new PhabricatorMailingListQuery()) 19 ->setViewer($viewer) 20 ->withIDs(array($this->id)) 21 ->executeOne(); 22 if (!$list) { 23 return new Aphront404Response(); 24 } 25 } else { 26 $page_title = pht('Create Mailing List'); 27 $list = new PhabricatorMetaMTAMailingList(); 28 } 29 30 $e_email = true; 31 $e_uri = null; 32 $e_name = true; 33 $errors = array(); 34 35 $crumbs = $this->buildApplicationCrumbs(); 36 37 if ($request->isFormPost()) { 38 $list->setName($request->getStr('name')); 39 $list->setEmail($request->getStr('email')); 40 $list->setURI($request->getStr('uri')); 41 42 $e_email = null; 43 $e_name = null; 44 45 if (!strlen($list->getEmail())) { 46 $e_email = pht('Required'); 47 $errors[] = pht('Email is required.'); 48 } 49 50 if (!strlen($list->getName())) { 51 $e_name = pht('Required'); 52 $errors[] = pht('Name is required.'); 53 } else if (preg_match('/[ ,]/', $list->getName())) { 54 $e_name = pht('Invalid'); 55 $errors[] = pht('Name must not contain spaces or commas.'); 56 } 57 58 if ($list->getURI()) { 59 if (!PhabricatorEnv::isValidWebResource($list->getURI())) { 60 $e_uri = pht('Invalid'); 61 $errors[] = pht('Mailing list URI must point to a valid web page.'); 62 } 63 } 64 65 if (!$errors) { 66 try { 67 $list->save(); 68 return id(new AphrontRedirectResponse()) 69 ->setURI($this->getApplicationURI()); 70 } catch (AphrontDuplicateKeyQueryException $ex) { 71 $e_email = pht('Duplicate'); 72 $errors[] = pht('Another mailing list already uses that address.'); 73 } 74 } 75 } 76 77 $form = new AphrontFormView(); 78 $form->setUser($request->getUser()); 79 if ($list->getID()) { 80 $form->setAction($this->getApplicationURI('/edit/'.$list->getID().'/')); 81 } else { 82 $form->setAction($this->getApplicationURI('/edit/')); 83 } 84 85 $form 86 ->appendChild( 87 id(new AphrontFormTextControl()) 88 ->setLabel(pht('Email')) 89 ->setName('email') 90 ->setValue($list->getEmail()) 91 ->setCaption(pht('Email will be delivered to this address.')) 92 ->setError($e_email)) 93 ->appendChild( 94 id(new AphrontFormTextControl()) 95 ->setLabel(pht('Name')) 96 ->setName('name') 97 ->setError($e_name) 98 ->setCaption(pht('Human-readable display and autocomplete name.')) 99 ->setValue($list->getName())) 100 ->appendChild( 101 id(new AphrontFormTextControl()) 102 ->setLabel(pht('URI')) 103 ->setName('uri') 104 ->setError($e_uri) 105 ->setCaption(pht('Optional link to mailing list archives or info.')) 106 ->setValue($list->getURI())) 107 ->appendChild( 108 id(new AphrontFormSubmitControl()) 109 ->setValue(pht('Save')) 110 ->addCancelButton($this->getApplicationURI())); 111 112 if ($list->getID()) { 113 $crumbs->addTextCrumb(pht('Edit Mailing List')); 114 } else { 115 $crumbs->addTextCrumb(pht('Create Mailing List')); 116 } 117 118 $form_box = id(new PHUIObjectBoxView()) 119 ->setHeaderText($page_title) 120 ->setFormErrors($errors) 121 ->setForm($form); 122 123 return $this->buildApplicationPage( 124 array( 125 $crumbs, 126 $form_box, 127 ), 128 array( 129 'title' => $page_title, 130 )); 131 } 132 133 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |