mirror of
https://github.com/EGroupware/egroupware.git
synced 2025-06-26 12:51:52 +02:00
Check & avoid duplicates when re-indexing options
This commit is contained in:
parent
d10025b462
commit
d1106a31fc
@ -186,6 +186,7 @@ class etemplate_widget_menupopup extends etemplate_widget
|
|||||||
* Fix already html-encoded options, eg. "&nbps"
|
* Fix already html-encoded options, eg. "&nbps"
|
||||||
*
|
*
|
||||||
* @param array $options
|
* @param array $options
|
||||||
|
* @param boolean $use_array_of_options Re-indexes options, making everything more complicated
|
||||||
*/
|
*/
|
||||||
public static function fix_encoded_options(array &$options, $use_array_of_objects=null)
|
public static function fix_encoded_options(array &$options, $use_array_of_objects=null)
|
||||||
{
|
{
|
||||||
@ -193,6 +194,25 @@ class etemplate_widget_menupopup extends etemplate_widget
|
|||||||
|
|
||||||
foreach($options as $value => &$label)
|
foreach($options as $value => &$label)
|
||||||
{
|
{
|
||||||
|
// Of course once we re-index the options, we can't detect duplicates
|
||||||
|
// so check here, as we re-index
|
||||||
|
// Duplicates might happen if app programmer isn't paying attention and
|
||||||
|
// either uses the same ID in the template, or adds the options twice
|
||||||
|
if(is_numeric($value) && is_array($label) && !array_key_exists('value',$label))
|
||||||
|
{
|
||||||
|
$check_value = array_key_exists('value', $label) ? $label['value'] : $value;
|
||||||
|
if($value == $check_value)
|
||||||
|
{
|
||||||
|
foreach($options as $key => $existing)
|
||||||
|
{
|
||||||
|
if(is_array($existing) && $existing['value'] == $check_value && $key != $value)
|
||||||
|
{
|
||||||
|
unset($options[$value]);
|
||||||
|
continue 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if (is_null($use_array_of_objects) && is_numeric($value))
|
if (is_null($use_array_of_objects) && is_numeric($value))
|
||||||
{
|
{
|
||||||
$options = $backup_options;
|
$options = $backup_options;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user