Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
iblockelement.php
1<?php
3
7
8Loc::loadMessages(__FILE__);
9
11{
18 public static function renderControlOptions(FieldType $fieldType, $callbackFunctionName, $value)
19 {
20 if (is_array($value))
21 {
22 reset($value);
23 $valueTmp = (int) current($value);
24 }
25 else
26 {
27 $valueTmp = (int) $value;
28 }
29
30 $iblockId = 0;
31 if ($valueTmp > 0)
32 {
33 $idKey = ($fieldType->getType() === 'UF:iblock_section') ? 'SECTION_ID' : 'ID';
34 $elementIterator = \CIBlockElement::getList([], [$idKey => $valueTmp], false, false, array('ID', 'IBLOCK_ID'));
35 if ($element = $elementIterator->fetch())
36 {
37 $iblockId = $element['IBLOCK_ID'];
38 }
39 }
40
41 if ($iblockId <= 0 && (int) $fieldType->getOptions() > 0)
42 {
43 $iblockId = (int) $fieldType->getOptions();
44 }
45
46 $defaultIBlockId = 0;
47
48 $result = '<select id="WFSFormOptionsX" onchange="'
49 .Main\Text\HtmlFilter::encode($callbackFunctionName).'(this.options[this.selectedIndex].value)">';
50
51 $iblockTypeIterator = \CIBlockParameters::getIBlockTypes();
52 foreach ($iblockTypeIterator as $iblockTypeId => $iblockTypeName)
53 {
54 $result .= '<optgroup label="'.Main\Text\HtmlFilter::encode($iblockTypeName).'">';
55
56 $iblockIterator = \CIBlock::getList(['SORT' => 'ASC'], ['TYPE' => $iblockTypeId, 'ACTIVE' => 'Y']);
57 while ($iblock = $iblockIterator->fetch())
58 {
59 $result .= '<option value="'.$iblock['ID'].'"'.(($iblock['ID'] == $iblockId) ? ' selected' : '').'>'
60 .Main\Text\HtmlFilter::encode($iblock['NAME']).'</option>';
61 if (($defaultIBlockId <= 0) || ($iblock['ID'] == $iblockId))
62 $defaultIBlockId = $iblock['ID'];
63 }
64
65 $result .= '</optgroup>';
66 }
67 $result .= '</select><!--__defaultOptionsValue:'.$defaultIBlockId.'--><!--__modifyOptionsPromt:'
68 .Loc::getMessage('BP_FIELDTYPE_UF_INFOBLOCK').'-->';
69 $fieldType->setOptions($defaultIBlockId);
70
71 return $result;
72 }
73}
static renderControlOptions(FieldType $fieldType, $callbackFunctionName, $value)
static loadMessages($file)
Definition loc.php:64
static encode($string, $flags=ENT_COMPAT, $doubleEncode=true)