Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
Element.php
1<?php
2
4
9
11{
12 public static function renderSelector(array $property, array|int|string|null $values, array $config): string
13 {
14 $rowId = trim((string)($config['ROW_ID'] ?? ''));
15 $fieldName = trim((string)($config['FIELD_NAME'] ?? ''));
16 if ($fieldName === '')
17 {
18 return '';
19 }
20
21 if (($property['PROPERTY_TYPE'] ?? '') !== Iblock\PropertyTable::TYPE_ELEMENT)
22 {
23 return '';
24 }
25
26 $containerId =
27 $rowId . ($rowId !== '' ? '_' : '')
28 . $fieldName . '_container'
29 ;
30
31 if (!is_array($values))
32 {
33 $values = !empty($values) ? [$values] : [];
34 }
35 Type\Collection::normalizeArrayValuesByInt($values, false);
36
37 $multiple = ($property['MULTIPLE'] ?? 'N') === 'Y';
38
39 $config['SEARCH_TITLE'] = (string)($config['SEARCH_TITLE'] ?? '');
40 if ($config['SEARCH_TITLE'] === '')
41 {
42 $config['SEARCH_TITLE'] = Loc::getMessage('IBLOCK_UI_INPUT_ELEMENT_SELECTOR_SEARCH_TITLE');
43 }
44 $config['SEARCH_SUBTITLE'] = (string)($config['SEARCH_SUBTITLE'] ?? '');
45 if ($config['SEARCH_SUBTITLE'] === '')
46 {
47 $config['SEARCH_SUBTITLE'] = Loc::getMessage('IBLOCK_UI_INPUT_ELEMENT_SELECTOR_SEARCH_SUBTITLE');
48 }
49 // TODO: replace entityId value to constant
50 $config['ENTITY_ID'] = (string)($config['ENTITY_ID'] ?? 'iblock-property-element');
51
52 $config['CHANGE_EVENTS'] ??= [];
53 if (!is_array($config['CHANGE_EVENTS']))
54 {
55 $config['CHANGE_EVENTS'] = is_string($config['CHANGE_EVENTS']) ? [$config['CHANGE_EVENTS']] : [];
56 }
57
58 $config = \CUtil::PhpToJSObject(
59 [
60 'containerId' => $containerId,
61 'fieldName' => $fieldName . ($multiple ? '[]' : ''),
62 'multiple' => $multiple,
63 'collectionType' => 'int',
64 'selectedItems' => $values,
65 'iblockId' => (int)($property['LINK_IBLOCK_ID'] ?? 0),
66 'userType' => (string)($property['USER_TYPE'] ?? ''),
67 'entityId' => $config['ENTITY_ID'],
68 'searchMessages' => [
69 'title' => $config['SEARCH_TITLE'],
70 'subtitle' => $config['SEARCH_SUBTITLE'],
71 ],
72 'changeEvents' => $config['CHANGE_EVENTS'],
73 ],
74 false,
75 true,
76 true
77 );
78
79 UI\Extension::load('iblock.field-selector');
80
81 return <<<HTML
82 <div id="$containerId"></div>
83 <script>
84 (function() {
85 const selector = new BX.Iblock.FieldSelector({$config});
86 selector.render();
87 })();
88 </script>
89HTML;
90 }
91}
static renderSelector(array $property, array|int|string|null $values, array $config)
Definition Element.php:12
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29