mirror of
https://github.com/EGroupware/egroupware.git
synced 2025-02-08 14:30:05 +01:00
convert associative array to a real array with value attribute, to preserve the order of numeric keys
This commit is contained in:
parent
7a17dcc7cb
commit
af0c557cc5
@ -105,20 +105,24 @@ class Link extends Etemplate\Widget
|
|||||||
*/
|
*/
|
||||||
public static function ajax_link_search($app, $type, $pattern, $options=array())
|
public static function ajax_link_search($app, $type, $pattern, $options=array())
|
||||||
{
|
{
|
||||||
$options['type'] = $type ? $type : $options['type'];
|
$options['type'] = $type ?: $options['type'];
|
||||||
if(!$options['num_rows']) $options['num_rows'] = 1000;
|
if(!$options['num_rows']) $options['num_rows'] = 100;
|
||||||
|
|
||||||
$links = Api\Link::query($app, $pattern, $options);
|
$links = Api\Link::query($app, $pattern, $options);
|
||||||
|
|
||||||
// Add ' ' to key so javascript does not parse it as a number.
|
|
||||||
// This preserves the order set by the application.
|
|
||||||
$linksc = array_combine(array_map(function($k)
|
|
||||||
{
|
|
||||||
return (string)" ".$k;
|
|
||||||
}, array_keys($links)), $links);
|
|
||||||
|
|
||||||
$response = Api\Json\Response::get();
|
$response = Api\Json\Response::get();
|
||||||
$response->data($linksc);
|
// convert associative array to a real array with value attribute, to preserve the order of numeric keys
|
||||||
|
$response->data(array_values(array_map(static function($key, $value)
|
||||||
|
{
|
||||||
|
if (is_array($value))
|
||||||
|
{
|
||||||
|
return $value+['value' => $key];
|
||||||
|
}
|
||||||
|
return [
|
||||||
|
'value' => $key,
|
||||||
|
'label' => $value,
|
||||||
|
];
|
||||||
|
}, array_keys($links), $links)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user