Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F93949803
PhabricatorStandardSelectCustomFieldDatasource.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
Mon, Dec 2, 18:52
Size
2 KB
Mime Type
text/x-php
Expires
Wed, Dec 4, 18:52 (2 d)
Engine
blob
Format
Raw Data
Handle
22727667
Attached To
rPH Phabricator
PhabricatorStandardSelectCustomFieldDatasource.php
View Options
<?php
final
class
PhabricatorStandardSelectCustomFieldDatasource
extends
PhabricatorTypeaheadDatasource
{
public
function
getBrowseTitle
()
{
return
pht
(
'Browse Values'
);
}
public
function
getPlaceholderText
()
{
return
pht
(
'Type a field value...'
);
}
public
function
getDatasourceApplicationClass
()
{
return
null
;
}
public
function
loadResults
()
{
$viewer
=
$this
->
getViewer
();
$class
=
$this
->
getParameter
(
'object'
);
if
(!
class_exists
(
$class
))
{
throw
new
Exception
(
pht
(
'Custom field class "%s" does not exist.'
,
$class
));
}
$reflection
=
new
ReflectionClass
(
$class
);
$interface
=
'PhabricatorCustomFieldInterface'
;
if
(!
$reflection
->
implementsInterface
(
$interface
))
{
throw
new
Exception
(
pht
(
'Custom field class "%s" does not implement interface "%s".'
,
$class
,
$interface
));
}
$role
=
$this
->
getParameter
(
'role'
);
if
(!
strlen
(
$role
))
{
throw
new
Exception
(
pht
(
'No custom field role specified.'
));
}
$object
=
newv
(
$class
,
array
());
$field_list
=
PhabricatorCustomField
::
getObjectFields
(
$object
,
$role
);
$field_key
=
$this
->
getParameter
(
'key'
);
if
(!
strlen
(
$field_key
))
{
throw
new
Exception
(
pht
(
'No custom field key specified.'
));
}
$field
=
null
;
foreach
(
$field_list
->
getFields
()
as
$candidate_field
)
{
if
(
$candidate_field
->
getFieldKey
()
==
$field_key
)
{
$field
=
$candidate_field
;
break
;
}
}
if
(
$field
===
null
)
{
throw
new
Exception
(
pht
(
'No field with field key "%s" exists for objects of class "%s" with '
.
'custom field role "%s".'
,
$field_key
,
$class
,
$role
));
}
if
(!(
$field
instanceof
PhabricatorStandardCustomFieldSelect
))
{
$field
=
$field
->
getProxy
();
if
(!(
$field
instanceof
PhabricatorStandardCustomFieldSelect
))
{
throw
new
Exception
(
pht
(
'Field "%s" is not a standard select field, nor a proxy of a '
.
'standard select field.'
,
$field_key
));
}
}
$options
=
$field
->
getOptions
();
$results
=
array
();
foreach
(
$options
as
$key
=>
$option
)
{
$results
[]
=
id
(
new
PhabricatorTypeaheadResult
())
->
setName
(
$option
)
->
setPHID
(
$key
);
}
return
$this
->
filterResultsAgainstTokens
(
$results
);
}
}
Event Timeline
Log In to Comment