3
final class PhabricatorMailingListsEditController
4
extends PhabricatorMailingListsController {
6
public function handleRequest(AphrontRequest $request) {
7
$request = $this->getRequest();
8
$viewer = $request->getUser();
10
$this->requireApplicationCapability(
11
PhabricatorMailingListsManageCapability::CAPABILITY);
13
$list_id = $request->getURIData('id');
15
$page_title = pht('Edit Mailing List');
16
$list = id(new PhabricatorMailingListQuery())
18
->withIDs(array($list_id))
21
return new Aphront404Response();
24
$page_title = pht('Create Mailing List');
25
$list = new PhabricatorMetaMTAMailingList();
33
$crumbs = $this->buildApplicationCrumbs();
35
if ($request->isFormPost()) {
36
$list->setName($request->getStr('name'));
37
$list->setEmail($request->getStr('email'));
38
$list->setURI($request->getStr('uri'));
43
if (!strlen($list->getEmail())) {
44
$e_email = pht('Required');
45
$errors[] = pht('Email is required.');
48
if (!strlen($list->getName())) {
49
$e_name = pht('Required');
50
$errors[] = pht('Name is required.');
51
} else if (preg_match('/[ ,]/', $list->getName())) {
52
$e_name = pht('Invalid');
53
$errors[] = pht('Name must not contain spaces or commas.');
56
if ($list->getURI()) {
57
if (!PhabricatorEnv::isValidRemoteURIForLink($list->getURI())) {
58
$e_uri = pht('Invalid');
59
$errors[] = pht('Mailing list URI must point to a valid web page.');
66
return id(new AphrontRedirectResponse())
67
->setURI($this->getApplicationURI());
68
} catch (AphrontDuplicateKeyQueryException $ex) {
69
$e_email = pht('Duplicate');
70
$errors[] = pht('Another mailing list already uses that address.');
75
$form = new AphrontFormView();
76
$form->setUser($request->getUser());
78
$form->setAction($this->getApplicationURI('/edit/'.$list->getID().'/'));
80
$form->setAction($this->getApplicationURI('/edit/'));
85
id(new AphrontFormTextControl())
86
->setLabel(pht('Email'))
88
->setValue($list->getEmail())
89
->setCaption(pht('Email will be delivered to this address.'))
92
id(new AphrontFormTextControl())
93
->setLabel(pht('Name'))
96
->setCaption(pht('Human-readable display and autocomplete name.'))
97
->setValue($list->getName()))
99
id(new AphrontFormTextControl())
100
->setLabel(pht('URI'))
103
->setCaption(pht('Optional link to mailing list archives or info.'))
104
->setValue($list->getURI()))
106
id(new AphrontFormSubmitControl())
107
->setValue(pht('Save'))
108
->addCancelButton($this->getApplicationURI()));
110
if ($list->getID()) {
111
$crumbs->addTextCrumb(pht('Edit Mailing List'));
113
$crumbs->addTextCrumb(pht('Create Mailing List'));
116
$form_box = id(new PHUIObjectBoxView())
117
->setHeaderText($page_title)
118
->setFormErrors($errors)
121
return $this->buildApplicationPage(
127
'title' => $page_title,