Select :: renderControl: Bitrix method

      
<?php 
//  Bitrix\Bizproc\BaseType\Select :: renderControl()
//  /dist/bitrix/modules/bizproc/lib/basetype/select.php:128

    
protected static function renderControl(FieldType $fieldType, array $field$value$allowSelection$renderMode)
    {
        
$selectorValue null;
        
$typeValue = [];
        if (!
is_array($value))
        {
            
$value = (array) $value;
        }

        if (\
CBPHelper::isAssociativeArray($value))
        {
            
$value array_keys($value);
        }

        foreach (
$value as $v)
        {
            if (
$allowSelection && \CBPActivity::isExpression($v))
            {
                
$selectorValue $v;
            }
            else
            {
                
$typeValue[] = (string)$v;
            }
        }

        
// need to show at least one control
        
if (empty($typeValue))
        {
            
$typeValue[] = null;
        }

        
$className = static::generateControlClassName($fieldType$field);

        
$renderResult '<select id="'.htmlspecialcharsbx(static::generateControlId($field))
            .
'" class="'.htmlspecialcharsbx($className)
            .
'" name="'.htmlspecialcharsbx(static::generateControlName($field))
            .(
$fieldType->isMultiple() ? '[]' '').'"'.($fieldType->isMultiple() ? ' size="5" multiple' '').'>';

        if (!
$fieldType->isMultiple())
        {
            
$renderResult .= '<option value="">['.Loc::getMessage('BPCGHLP_NOT_SET').']</option>';
        }

        
$settings = static::getFieldSettings($fieldType);
        
$groups $settings['Groups'] ? $settings['Groups'] : null;

        if(
is_array($groups) && !empty($groups))
        {
            foreach(
$groups as $group)
            {
                if(!
is_array($group))
                {
                    continue;
                }

                
$name = isset($group['name']) ? $group['name'] : '';

                if(
$name !== '')
                {
                    
$renderResult .= '<optgroup label="'.htmlspecialcharsbx($name).'">';
                }

                
$options = isset($group['items']) && is_array($group['items']) ? $group['items'] : array();
                foreach(
$options as $k => $v)
                {
                    
$renderResult .= '<option value="';
                    
$renderResult .= htmlspecialcharsbx($k);
                    
$renderResult .= '"';

                    if(
in_array((string)$k$typeValuetrue))
                    {
                        
$renderResult .= ' selected';
                    }

                    
$renderResult .= '>';
                    
$renderResult .= htmlspecialcharsbx($v);
                    
$renderResult .= '</option>';
                }

                if(
$name !== '')
                {
                    
$renderResult .= '</optgroup>';
                }
            }
        }
        else
        {
            
$options = static::getFieldOptions($fieldType);
            foreach (
$options as $k => $v)
            {
                
$renderResult .= '<option value="'.htmlspecialcharsbx($k).'"'.(in_array((string)$k$typeValue) ? ' selected' '').'>'.htmlspecialcharsbx(htmlspecialcharsback($v)).'</option>';
            }
        }

        
$renderResult .= '</select>';

        if (
$allowSelection)
        {
            
$renderResult .= static::renderControlSelector($field$selectorValuetrue''$fieldType);
        }

        return 
$renderResult;
    }