23 private array $entities;
27 parent::__construct($columnIds, $settings);
29 $this->preloadResources();
42 private function preloadResources(): void
44 Asset::getInstance()->addJs(
'/bitrix/components/bitrix/ui.image.input/templates/.default/script.js');
45 Asset::getInstance()->addCss(
'/bitrix/components/bitrix/ui.image.input/templates/.default/style.css');
48 private function getIblockId(): int
53 private function getOffersIblockId(): ?int
67 $this->loadEntities($rowList);
69 foreach ($rowList as &$row)
71 $id = (int)($row[
'data'][
'ID'] ?? 0);
72 $type = $row[
'data'][
'ROW_TYPE'] ??
null;
76 $entity = $this->entities[$id] ??
null;
78 $row[
'columns'] ??= [];
82 if ($id === 0 || $type !== RowType::ELEMENT || !isset($entity))
84 $row[
'data'][$columnId] =
null;
85 $row[
'columns'][$columnId] =
null;
90 foreach ($entity->getFrontImageCollection() as $image)
92 $uri =
new Uri($image->getSource());
93 $imagesSrc[] = (string)$uri->toAbsolute();
96 $row[
'data'][$columnId] = join(
', ', $imagesSrc);
97 $row[
'columns'][$columnId] = join(
', ', $imagesSrc);
101 $imageInput =
new ImageInput($entity);
103 $html = $imageInput->getFormattedField();
105 $row[
'data'][
'~' . $columnId] = $html[
'input'];
106 $row[
'columns'][$columnId] = $html[
'preview'];
121 private function loadEntities(array $rowList): void
123 $this->entities = [];
125 $productToOfferId = $this->
getSettings()->getSelectedProductOfferIds();
126 $offerToProductId = array_flip($productToOfferId);
129 foreach ($rowList as $row)
131 $id = (int)($row[
'data'][
'ID'] ?? 0);
137 $type = $row[
'data'][
'ROW_TYPE'] ??
null;
138 if ($type !== RowType::ELEMENT)
144 if (isset($productToOfferId[$id]))
146 $id = $productToOfferId[$id];
157 $repository = ServiceContainer::getProductRepository($this->getIblockId());
158 if (isset($repository))
160 $items = $repository->getEntitiesBy([
165 foreach ($items as $item)
171 $this->entities[$item->getId()] = $item;
175 $offersIblockId = $this->getOffersIblockId();
177 isset($offersIblockId)
178 ? ServiceContainer::getSkuRepository($offersIblockId)
181 if (isset($repository))
183 $items = $repository->getEntitiesBy([
188 foreach ($items as $item)
194 $productId = $offerToProductId[$item->getId()];
prepareRows(array $rowList)