32 private static ?array $currentFieldSet =
null;
34 private static array $defaultFieldList = [
35 Catalog\Product\SystemField\MarkingCodeGroup::class,
36 Catalog\Product\SystemField\ProductMapping::class,
45 $createResult = self::create();
46 if (!$createResult->isSuccess())
48 $result =
'\Bitrix\Catalog\Product\SystemField::execAgent();';
60 self::$currentFieldSet =
null;
62 $fieldList = self::getBuildedFieldList();
63 if (empty($fieldList))
65 $result->setData([
'STATUS' => self::STATUS_FINAL]);
69 foreach ($fieldList as $field)
71 $internalResult = $field::create();
72 if (!$internalResult->isSuccess())
74 foreach ($internalResult->getErrors() as $error)
76 $result->addError($error);
81 $result->setData([
'STATUS' => self::STATUS_FINAL]);
89 public static function delete(): void
91 self::$currentFieldSet =
null;
97 foreach (self::getCurrentFieldSet($operation) as $field)
99 $result = array_merge(
101 $field::getOperationSelectFieldList($operation)
112 private static function getCurrentFieldSet(
string $operation): array
114 self::loadCurrentFieldSet($operation);
116 return self::$currentFieldSet[$operation] ?? [];
119 private static function getDefaultFieldSet(): array
122 self::OPERATION_PROVIDER =>
null,
123 self::OPERATION_IMPORT =>
null,
124 self::OPERATION_EXPORT =>
null,
128 private static function loadCurrentFieldSet(
string $operation): void
130 if (self::$currentFieldSet ===
null)
132 self::$currentFieldSet = self::getDefaultFieldSet();
134 if (!array_key_exists($operation, self::$currentFieldSet))
138 if (self::$currentFieldSet[$operation] ===
null)
140 self::$currentFieldSet[$operation] = [];
142 $fieldList = self::getBuildedFieldList();
143 if (!empty($fieldList))
145 foreach ($fieldList as $field)
147 if ($field::checkAllowedOperation($operation) && $field::isExists())
149 self::$currentFieldSet[$operation][] = $field;
160 return self::getSelectFields(self::OPERATION_PROVIDER);
165 return self::getSelectFields(self::OPERATION_EXPORT);
170 return self::getSelectFields(self::OPERATION_IMPORT);
181 return self::getProviderSelectFields();
192 public static function convertRow(array &$row,
string $operation = self::OPERATION_PROVIDER): void
194 self::prepareRow($row, $operation);
197 public static function prepareRow(array &$row,
string $operation = self::OPERATION_IMPORT): void
199 foreach (self::getCurrentFieldSet($operation) as $field)
201 $row = $field::prepareValue($operation, $row);
218 $fieldList = self::getBuildedFieldList();
219 if (empty($fieldList))
225 foreach ($fieldList as $field)
227 $action = $field::getGridAction($panel);
233 unset($action, $field, $fieldList);
235 return (!empty($result) ? $result :
null);
238 public static function getByUserFieldName(
string $fieldName): ?string
240 $fieldList = self::getBuildedFieldList();
241 if (empty($fieldList))
247 foreach ($fieldList as $field)
249 $baseParams = $field::getUserFieldBaseParam();
250 if ($baseParams[
'FIELD_NAME'] === $fieldName)
257 unset($baseParams, $field, $fieldList);
264 $fieldList = self::getBuildedFieldList();
265 if (empty($fieldList))
270 $resultMode = self::DESCRIPTION_MODE_FULL;
271 if (isset($config[
'RESULT_MODE']) && is_string($config[
'RESULT_MODE']))
273 $resultMode = $config[
'RESULT_MODE'];
277 foreach ($fieldList as $field)
280 $field::checkRestictions($restrictions)
281 && $field::isExists()
284 $data = $field::getUserFieldBaseParam();
287 case self::DESCRIPTION_MODE_FIELD_NAME:
288 $result[] = $data[
'FIELD_NAME'];
290 case self::DESCRIPTION_MODE_UI_LIST:
292 $data[
'FIELD_NAME'] => $field::getTitle(),
295 case self::DESCRIPTION_MODE_UI_FORM_EDITOR:
297 'name' => $data[
'FIELD_NAME'],
300 case self::DESCRIPTION_MODE_UI_FIELDS:
301 $result[] = $field::getUiDescription($restrictions);
303 case self::DESCRIPTION_MODE_CLASSNAME:
304 $result[$data[
'FIELD_NAME']] = $field;
306 case self::DESCRIPTION_MODE_FULL:
308 $result[$data[
'FIELD_NAME']] = $data;
313 unset($field, $fieldList);
320 return self::getFieldsByRestrictions(
323 'RESULT_MODE' => self::DESCRIPTION_MODE_FIELD_NAME,
330 $fieldList = self::getBuildedFieldList();
331 if (empty($fieldList))
337 foreach ($fieldList as $field)
339 if ($field::isExists())
341 $data = $field::getUserFieldBaseParam();
342 $result[$data[
'FIELD_NAME']] = $field::checkRestictions($restrictions);
345 unset($field, $fieldList);
352 $fieldList = self::getBuildedFieldList();
353 if (empty($fieldList))
359 foreach ($fieldList as $field)
361 $baseParams = $field::getUserFieldBaseParam();
362 $result[$baseParams[
'FIELD_NAME']] = $field::getAllowedProductTypeList();
364 unset($field, $fieldList);
374 public static function getGroupActionRequest(
ProductGroupAction $panel,
string $fieldName): ?array
383 $field = self::getByUserFieldName($fieldName);
389 return $field::getGroupActionRequest($panel);
401 $result =
new ORM\EventResult();
405 $primary = $event->getParameter(
'primary');
406 if (!empty($primary))
408 $iterator = Highload\HighloadBlockTable::getList([
409 'filter' => $primary,
411 $row = $iterator->fetch();
416 $fieldList = self::getBuildedFieldList();
417 foreach ($fieldList as $field)
423 if (!$field::isAllowed() || !$field::isExists())
427 $config = $field::getConfig();
429 if ($row[
'NAME'] === $config[
'HIGHLOADBLOCK'][
'NAME'])
433 'BX_CATALOG_PRODUCT_SYSTEMFIELD_ERR_CANNOT_DELETE_HIGHLOADBLOCK',
434 [
'#NAME#' => $row[
'NAME']]
440 unset($field, $fieldList);
459 $result =
new ORM\EventResult();
463 $primary = $event->getParameter(
'primary');
464 $fields = $event->getParameter(
'fields');
465 if (!empty($primary))
467 $iterator = Highload\HighloadBlockTable::getList([
468 'filter' => $primary,
470 $row = $iterator->fetch();
474 $fieldList = self::getBuildedFieldList();
475 foreach ($fieldList as $field)
481 if (!$field::isAllowed() || !$field::isExists())
485 $config = $field::getConfig();
487 if ($row[
'NAME'] === $config[
'HIGHLOADBLOCK'][
'NAME'])
490 (isset($fields[
'NAME']) && $row[
'NAME'] != $fields[
'NAME'])
491 || (isset($fields[
'TABLE_NAME']) && $row[
'TABLE_NAME'] != $fields[
'TABLE_NAME'])
496 'BX_CATALOG_PRODUCT_SYSTEMFIELD_ERR_CANNOT_UPDATE_HIGHLOADBLOCK',
497 [
'#NAME#' => $row[
'NAME']]
504 unset($field, $fieldList);
518 public static function handlerHighloadBlockBeforeUninstall(Main\
Event $event): Main\
EventResult
522 $module = $event->getParameter(
'module');
523 if ($module ===
'highloadblock')
525 $fieldList = self::getBuildedFieldList();
526 foreach ($fieldList as $field)
532 if (!$field::isAllowed() || !$field::isExists())
536 $config = $field::getConfig();
538 $fieldType = $field::getTypeId();
539 $row = $fieldType::getStorageTable($config[
'HIGHLOADBLOCK']);
542 $blockNames[] = $config[
'HIGHLOADBLOCK'][
'NAME'];
544 unset($row, $fieldType, $config);
550 if (empty($blockNames))
552 return new Main\EventResult(Main\EventResult::SUCCESS);
556 if (count($blockNames) === 1)
559 'BX_CATALOG_PRODUCT_SYSTEMFIELD_ERR_DISALLOW_UNINSTALL_HIGHLOADBLOCK',
561 '#NAME#' => reset($blockNames),
568 'BX_CATALOG_PRODUCT_SYSTEMFIELD_ERR_DISALLOW_UNINSTALL_HIGHLOADBLOCK_LIST',
570 '#NAME#' => implode(
', ', $blockNames),
575 return new Main\EventResult(
576 Main\EventResult::ERROR,
588 protected static function getBuildedFieldList(): array
593 self::$defaultFieldList,
594 self::getExternalFieldList()
597 foreach ($list as $className)
599 if ($className::isAllowed())
601 $result[] = $className;
616 self::EVENT_ID_BUILD_FIELD_LIST,
620 $eventResult = $event->getResults();
621 if (!empty($eventResult) && is_array($eventResult))
623 foreach ($eventResult as $row)
625 if ($row->getType() != Main\EventResult::SUCCESS)
629 $classList = $row->getParameters();
630 if (empty($classList) || !is_array($classList))
634 foreach ($classList as $item)
636 if (!is_string($item))
643 || !class_exists($item)
657 public static function renderAdminEditForm(array $product, array $config): ?string
659 if (!isset($product[
'ID']) || !isset($product[
'IBLOCK_ID']) || !isset($product[
'TYPE']))
663 $product[
'IBLOCK_ID'] = (int)$product[
'IBLOCK_ID'];
664 if ($product[
'IBLOCK_ID'] <= 0)
668 $product[
'PRODUCT_ID'] = (int)($product[
'PRODUCT_ID'] ?? \CIBlockElement::GetRealElement($product[
'ID']));
669 $product[
'TYPE'] = (int)$product[
'TYPE'];
671 $config[
'FROM_FORM'] = $config[
'FROM_FORM'] ??
false;
672 $config[
'ALLOW_EDIT'] = $config[
'ALLOW_EDIT'] ??
true;
674 $systemFields = self::getFieldsByRestrictions(
676 'TYPE' => $product[
'TYPE'],
677 'IBLOCK_ID' => $product[
'IBLOCK_ID'],
680 'RESULT_MODE' => self::DESCRIPTION_MODE_CLASSNAME,
683 if (empty($systemFields))
688 $userFieldManager = Main\UserField\Internal\UserFieldHelper::getInstance()->getManager();
689 $userFields = $userFieldManager->GetUserFields(
691 $product[
'PRODUCT_ID'],
694 if (empty($userFields))
705 foreach ($systemFields as $fieldName => $className)
707 $row = $userFields[$fieldName];
709 $row[
'VALUE_ID'] = $product[
'PRODUCT_ID'];
710 $row[
'EDIT_FORM_LABEL'] = $row[
'EDIT_FORM_LABEL'] ?? $row[
'FIELD_NAME'];
711 if (!$config[
'ALLOW_EDIT'])
713 $row[
'EDIT_IN_LIST'] =
'N';
716 $html = $className::renderAdminFormControl($row, $product, $config);
722 unset($row, $fieldName);
729 return self::getFieldsByRestrictions(
732 'RESULT_MODE' => self::DESCRIPTION_MODE_UI_FIELDS,
static getMessage($code, $replace=null, $language=null)