Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F455264
PhabricatorStandardSelectCustomFieldDatasource.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
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
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Mon, May 5, 6:47 AM (2 d)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
69883
Default Alt Text
PhabricatorStandardSelectCustomFieldDatasource.php (2 KB)
Attached To
Mode
rP Phorge
Attached
Detach File
Event Timeline
Log In to Comment