Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F1343255
HeraldNewController.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
HeraldNewController.php
View Options
<?php
final
class
HeraldNewController
extends
HeraldController
{
private
$contentType
;
private
$ruleType
;
public
function
willProcessRequest
(
array
$data
)
{
$this
->
contentType
=
idx
(
$data
,
'type'
);
$this
->
ruleType
=
idx
(
$data
,
'rule_type'
);
}
public
function
processRequest
()
{
$request
=
$this
->
getRequest
();
$user
=
$request
->
getUser
();
$this
->
requireApplicationCapability
(
HeraldCapabilityCreateRules
::
CAPABILITY
);
$can_global
=
$this
->
hasApplicationCapability
(
HeraldCapabilityManageGlobalRules
::
CAPABILITY
);
$content_type_map
=
HeraldAdapter
::
getEnabledAdapterMap
(
$user
);
if
(
empty
(
$content_type_map
[
$this
->
contentType
]))
{
$this
->
contentType
=
head_key
(
$content_type_map
);
}
$rule_type_map
=
HeraldRuleTypeConfig
::
getRuleTypeMap
();
if
(
empty
(
$rule_type_map
[
$this
->
ruleType
]))
{
$this
->
ruleType
=
HeraldRuleTypeConfig
::
RULE_TYPE_PERSONAL
;
}
// Reorder array to put "personal" first.
$rule_type_map
=
array_select_keys
(
$rule_type_map
,
array
(
HeraldRuleTypeConfig
::
RULE_TYPE_PERSONAL
,
))
+
$rule_type_map
;
if
(!
$can_global
)
{
$global_link
=
$this
->
explainApplicationCapability
(
HeraldCapabilityManageGlobalRules
::
CAPABILITY
,
pht
(
'You do not have permission to create or manage global rules.'
));
}
else
{
$global_link
=
null
;
}
$captions
=
array
(
HeraldRuleTypeConfig
::
RULE_TYPE_PERSONAL
=>
pht
(
'Personal rules notify you about events. You own them, but they can '
.
'only affect you. Personal rules only trigger for objects you have '
.
'permission to see.'
),
HeraldRuleTypeConfig
::
RULE_TYPE_GLOBAL
=>
phutil_implode_html
(
phutil_tag
(
'br'
),
array_filter
(
array
(
pht
(
'Global rules notify anyone about events. Global rules can '
.
'bypass access control policies and act on any object.'
),
$global_link
,
))),
);
$radio
=
id
(
new
AphrontFormRadioButtonControl
())
->
setLabel
(
pht
(
'Type'
))
->
setName
(
'rule_type'
)
->
setValue
(
$this
->
ruleType
);
foreach
(
$rule_type_map
as
$value
=>
$name
)
{
$disabled
=
(
$value
==
HeraldRuleTypeConfig
::
RULE_TYPE_GLOBAL
)
&&
(!
$can_global
);
$radio
->
addButton
(
$value
,
$name
,
idx
(
$captions
,
$value
),
$disabled
?
'disabled'
:
null
,
$disabled
);
}
$form
=
id
(
new
AphrontFormView
())
->
setUser
(
$user
)
->
setAction
(
'/herald/edit/'
)
->
appendChild
(
id
(
new
AphrontFormSelectControl
())
->
setLabel
(
pht
(
'New Rule for'
))
->
setName
(
'content_type'
)
->
setValue
(
$this
->
contentType
)
->
setOptions
(
$content_type_map
))
->
appendChild
(
$radio
)
->
appendChild
(
id
(
new
AphrontFormSubmitControl
())
->
setValue
(
pht
(
'Create Rule'
))
->
addCancelButton
(
$this
->
getApplicationURI
()));
$form_box
=
id
(
new
PHUIObjectBoxView
())
->
setHeaderText
(
pht
(
'Create Herald Rule'
))
->
setForm
(
$form
);
$crumbs
=
$this
->
buildApplicationCrumbs
()
->
addCrumb
(
id
(
new
PhabricatorCrumbView
())
->
setName
(
pht
(
'Create Rule'
)));
return
$this
->
buildApplicationPage
(
array
(
$crumbs
,
$form_box
,
),
array
(
'title'
=>
pht
(
'Create Herald Rule'
),
'device'
=>
true
,
));
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sun, Jul 6, 1:32 PM (2 d)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
317420
Default Alt Text
HeraldNewController.php (3 KB)
Attached To
Mode
rP Phorge
Attached
Detach File
Event Timeline
Log In to Comment