Esempio n. 1
0
 /**
  * @param FieldType $fieldType
  * @param array $field
  * @param mixed $value
  * @param bool $allowSelection
  * @param int $renderMode
  * @return string
  */
 protected static function renderControl(FieldType $fieldType, array $field, $value, $allowSelection, $renderMode)
 {
     $selectorValue = null;
     $typeValue = array();
     if (!is_array($value) || is_array($value) && \CBPHelper::isAssociativeArray($value)) {
         $value = array($value);
     }
     foreach ($value as $v) {
         if (\CBPActivity::isExpression($v)) {
             $selectorValue = $v;
         } else {
             $typeValue[] = $v;
         }
     }
     // need to show at least one control
     if (empty($typeValue)) {
         $typeValue[] = null;
     }
     $renderResult = '<select id="' . htmlspecialcharsbx(static::generateControlId($field)) . '" name="' . htmlspecialcharsbx(static::generateControlName($field)) . ($fieldType->isMultiple() ? '[]' : '') . '"' . ($fieldType->isMultiple() ? ' size="5" multiple' : '') . '>';
     if (!$fieldType->isRequired()) {
         $renderResult .= '<option value="">[' . Loc::getMessage('BPCGHLP_NOT_SET') . ']</option>';
     }
     $options = static::getFieldOptions($fieldType);
     foreach ($options as $k => $v) {
         $ind = array_search($k, $typeValue);
         $renderResult .= '<option value="' . htmlspecialcharsbx($k) . '"' . ($ind !== false ? ' selected' : '') . '>' . htmlspecialcharsbx($v) . '</option>';
     }
     $renderResult .= '</select>';
     if ($allowSelection) {
         $renderResult .= static::renderControlSelector($field, $selectorValue, true);
     }
     return $renderResult;
 }