12 private $isValueContainEntityId;
13 private $dialogOptions = [];
17 $this->isValueContainEntityId = (bool)($fieldOptions[
'ADD_ENTITY_ID_TO_RESULT'] ??
false);
18 $this->isMultiple = (bool)($fieldOptions[
'MULTIPLE'] ??
false);
19 $this->dialogOptions =
20 isset($fieldOptions[
'DIALOG_OPTIONS']) && is_array($fieldOptions[
'DIALOG_OPTIONS'])
21 ? $fieldOptions[
'DIALOG_OPTIONS']
32 public function getLabel(
string $value): string
40 return ($result[0] ??
'');
54 $entities = $this->dialogOptions[
'entities'] ?? [];
55 $staticItems = $this->dialogOptions[
'items'] ?? [];
57 $hasEntities = (is_array($entities) && !empty($entities));
58 $hasStaticItems = (is_array($staticItems) && !empty($staticItems));
61 (!$hasEntities && !$hasStaticItems)
71 $result = array_merge($result, $this->getLabelsFromEntities($entities, $values));
76 $result = array_merge($result, $this->getLabelsFromStaticItems($staticItems, $values));
82 private function getLabelsFromEntities(array $entities, array $values): array
85 foreach ($entities as $entityOptions)
90 $entityValues = $this->getSupposedEntityValues($entity->getId(), $values);
94 foreach ($entity->getProvider()->getItems($entityValues) as $item)
96 $itemTitles[$this->getItemId($item)] = $item->getTitle();
98 foreach ($values as $valueId)
100 $result[
'_labels'][] = $itemTitles[$valueId] ?? (
'#' . $valueId);
103 if (!$this->isValueContainEntityId)
113 private function getLabelsFromStaticItems(array $staticItems, $values)
118 foreach ($staticItems as $itemOptions)
120 $item =
new Item($itemOptions);
121 $itemEntityId = $item->getEntityId();
122 if (!isset($itemsByEntity[$itemEntityId]))
124 $itemsByEntity[$itemEntityId] = $this->getSupposedEntityValues($item->getEntityId(), $values);
126 if (in_array((
string)$item->getId(), $itemsByEntity[$itemEntityId],
true))
128 $result[] = $item->getTitle();
135 private function getSupposedEntityValues(
string $entityId, array $values): array
138 foreach ($values as $value)
140 if ($this->isValueContainEntityId)
142 $entityValue = $this->extractEntityValue((
string)$value, $entityId);
145 $result[] = $entityValue;
157 private function extractEntityValue(
string $value,
string $entityId)
161 $parsedValue = Json::decode($value);
163 isset($parsedValue[0])
164 && isset($parsedValue[1])
165 && $parsedValue[0] === $entityId
168 return $parsedValue[1];
171 catch (\
Bitrix\Main\ArgumentException $e)
178 private function getItemId(Item $item): string
180 if ($this->isValueContainEntityId)
182 return Json::encode([(
string)$item->getEntityId(), (
string)$item->getId()]);
186 return (
string)$item->getId();
static includeModule($moduleName)