Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F92670679
PhabricatorApplicationProfileMenuItem.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Fri, Nov 22, 15:09
Size
3 KB
Mime Type
text/x-php
Expires
Sun, Nov 24, 15:09 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
22483945
Attached To
rPH Phabricator
PhabricatorApplicationProfileMenuItem.php
View Options
<?php
final
class
PhabricatorApplicationProfileMenuItem
extends
PhabricatorProfileMenuItem
{
const
MENUITEMKEY
=
'application'
;
const
FIELD_APPLICATION
=
'application'
;
public
function
getMenuItemTypeIcon
()
{
return
'fa-globe'
;
}
public
function
getMenuItemTypeName
()
{
return
pht
(
'Application'
);
}
public
function
canAddToObject
(
$object
)
{
return
true
;
}
public
function
getDisplayName
(
PhabricatorProfileMenuItemConfiguration
$config
)
{
$application
=
$this
->
getApplication
(
$config
);
if
(!
$application
)
{
return
pht
(
'(Restricted/Invalid Application)'
);
}
$name
=
$this
->
getName
(
$config
);
if
(
strlen
(
$name
))
{
return
$name
;
}
return
$application
->
getName
();
}
public
function
buildEditEngineFields
(
PhabricatorProfileMenuItemConfiguration
$config
)
{
return
array
(
id
(
new
PhabricatorDatasourceEditField
())
->
setKey
(
self
::
FIELD_APPLICATION
)
->
setLabel
(
pht
(
'Application'
))
->
setIsRequired
(
true
)
->
setDatasource
(
new
PhabricatorApplicationDatasource
())
->
setIsRequired
(
true
)
->
setSingleValue
(
$config
->
getMenuItemProperty
(
'application'
)),
id
(
new
PhabricatorTextEditField
())
->
setKey
(
'name'
)
->
setLabel
(
pht
(
'Name'
))
->
setValue
(
$this
->
getName
(
$config
)),
);
}
private
function
getName
(
PhabricatorProfileMenuItemConfiguration
$config
)
{
return
$config
->
getMenuItemProperty
(
'name'
);
}
private
function
getApplication
(
PhabricatorProfileMenuItemConfiguration
$config
)
{
$viewer
=
$this
->
getViewer
();
$phid
=
$config
->
getMenuItemProperty
(
'application'
);
$app
=
id
(
new
PhabricatorApplicationQuery
())
->
setViewer
(
$viewer
)
->
withPHIDs
(
array
(
$phid
))
->
executeOne
();
return
$app
;
}
protected
function
newNavigationMenuItems
(
PhabricatorProfileMenuItemConfiguration
$config
)
{
$viewer
=
$this
->
getViewer
();
$app
=
$this
->
getApplication
(
$config
);
if
(!
$app
)
{
return
array
();
}
$is_installed
=
PhabricatorApplication
::
isClassInstalledForViewer
(
get_class
(
$app
),
$viewer
);
if
(!
$is_installed
)
{
return
array
();
}
$item
=
$this
->
newItem
()
->
setHref
(
$app
->
getApplicationURI
())
->
setName
(
$this
->
getDisplayName
(
$config
))
->
setIcon
(
$app
->
getIcon
());
return
array
(
$item
,
);
}
public
function
validateTransactions
(
PhabricatorProfileMenuItemConfiguration
$config
,
$field_key
,
$value
,
array
$xactions
)
{
$viewer
=
$this
->
getViewer
();
$errors
=
array
();
if
(
$field_key
==
self
::
FIELD_APPLICATION
)
{
if
(
$this
->
isEmptyTransaction
(
$value
,
$xactions
))
{
$errors
[]
=
$this
->
newRequiredError
(
pht
(
'You must choose an application.'
),
$field_key
);
}
foreach
(
$xactions
as
$xaction
)
{
$new
=
$xaction
[
'new'
];
if
(!
$new
)
{
continue
;
}
if
(
$new
===
$value
)
{
continue
;
}
$applications
=
id
(
new
PhabricatorApplicationQuery
())
->
setViewer
(
$viewer
)
->
withPHIDs
(
array
(
$new
))
->
execute
();
if
(!
$applications
)
{
$errors
[]
=
$this
->
newInvalidError
(
pht
(
'Application "%s" is not a valid application which you have '
.
'permission to see.'
,
$new
),
$xaction
[
'xaction'
]);
}
}
}
return
$errors
;
}
}
Event Timeline
Log In to Comment