48 private static ?array $fields =
null;
71 if (!static::isAllowed())
77 'ID' => static::getFieldId(),
78 'TYPE' => static::getTypeId(),
79 'TITLE' => static::getTitle(),
93 abstract public static function getConfig(): ?array;
99 $result = static::getTitleInternal();
101 return ($result ?? static::getUserFieldName(static::getFieldId()));
110 $row = static::load();
116 if (!static::isAllowed())
118 return static::getCommonError(
'CATALOG_SYSTEMFIELD_ERR_DISALLOWED_FIELD');
121 $description = static::getDescription();
123 $description ===
null
124 || empty($description[
'TYPE'])
125 || empty($description[
'ID'])
128 return static::getCommonError(
'CATALOG_SYSTEMFIELD_ERR_BAD_FIELD_DESCRIPTION');
130 if (!is_a($description[
'TYPE'],
Type\Base::class,
true))
132 return static::getCommonError(
'CATALOG_SYSTEMFIELD_ERR_BAD_FIELD_TYPE');
135 $className = $description[
'TYPE'];
137 $config = static::getConfig();
138 if ($config ===
null)
140 return static::getCommonError(
'CATALOG_SYSTEMFIELD_ERR_BAD_CONFIG_DESCRIPTION');
143 $result = $className::create($config);
144 if ($result->isSuccess())
146 static::updateProductFormConfiguration();
156 return static::TYPE_ID;
161 return static::FIELD_ID;
166 if (self::$bitrix24Include ===
null)
168 self::$bitrix24Include = Loader::includeModule(
'bitrix24');
171 return self::$bitrix24Include;
176 return self::FIELD_PREFIX.$id;
186 if (self::$languages ===
null)
188 self::$languages = [];
189 $iterator = LanguageTable::getList([
191 'filter' => [
'=ACTIVE' =>
'Y']
193 while ($row = $iterator->fetch())
195 self::$languages[] = $row[
'ID'];
197 unset($row, $iterator);
200 return self::$languages;
203 protected static function getMessages(
string $file, array $messageIds): array
205 $messageList = array_fill_keys(array_keys($messageIds), []);
206 $languages = self::getLanguages();
207 foreach ($languages as $languageId)
210 foreach ($messageIds as $index => $phrase)
212 $message = (string)($mess[$phrase] ??
null);
215 $messageList[$index][$languageId] = $message;
219 unset($message, $languageId, $languages);
227 $result->addError(
new Main\
Error(
230 [
'#TITLE#' => static::getTitle()]
238 if (!static::isAllowed())
243 $description = static::getDescription();
245 $description ===
null
246 || empty($description[
'TYPE'])
247 || empty($description[
'ID'])
253 !class_exists($description[
'TYPE'])
254 || !is_a($description[
'TYPE'],
Type\Base::class,
true))
259 $actionConfig = static::getGridActionConfig($panel);
260 if ($actionConfig ===
null)
265 $className = $description[
'TYPE'];
267 return $className::getGridAction($actionConfig);
275 public static function load(): ?array
277 if (self::$fields ===
null)
281 $className = get_called_class();
282 if (!array_key_exists($className, self::$fields))
284 self::$fields[$className] = self::loadInternal($className);
287 return self::$fields[$className];
292 self::$languages =
null;
293 self::$fields =
null;
294 self::$allowedProductTypeList =
null;
295 self::$allowedOperations =
null;
298 private static function loadInternal(
string $className): ?array
301 $config = $className::getUserFieldBaseParam();
306 if ($config[
'USER_TYPE_ID'] ===
null)
311 $iterator = Main\UserFieldTable::getList([
312 'select' => array_merge(
317 '=ENTITY_ID' => $config[
'ENTITY_ID'],
318 '=FIELD_NAME' => $config[
'FIELD_NAME'],
319 '=USER_TYPE_ID' => $config[
'USER_TYPE_ID'],
325 $row = $iterator->fetch();
326 unset($iterator, $config);
330 return static::afterLoadInternalModify($row);
338 $row[
'ID'] = (int)$row[
'ID'];
339 $row[
'SORT'] = (int)$row[
'SORT'];
343 if ($fieldName ===
'LANGUAGE_ID')
345 unset($row[$fieldName]);
349 if (isset($row[$fieldName]) && $row[$fieldName] ===
'')
351 $row[$fieldName] =
null;
361 if (self::$allowedProductTypeList ===
null)
363 self::$allowedProductTypeList = [];
365 $className = get_called_class();
366 if (!isset(self::$allowedProductTypeList[$className]))
368 self::$allowedProductTypeList[$className] = static::getAllowedProductTypeList();
371 return in_array($type, self::$allowedProductTypeList[$className],
true);
381 if (isset($restrictions[
'TYPE']))
383 if (!static::checkAllowedProductType($restrictions[
'TYPE']))
394 $field = static::getUserFieldBaseParam();
396 $value = Main\Context::getCurrent()->getRequest()->get($requestName);
402 if ($field[
'MULTIPLE'] ===
'Y' && !is_array($value))
407 return [$field[
'FIELD_NAME'] => $value];
412 if (self::$allowedOperations ===
null)
414 self::$allowedOperations = [];
416 $className = get_called_class();
417 if (!isset(self::$allowedOperations[$className]))
419 self::$allowedOperations[$className] = array_fill_keys(static::getAllowedOperations(),
true);
422 return isset(self::$allowedOperations[$className][$operation]);
435 public static function prepareValue(
string $operation, array $productRow): array
442 if (!static::isAllowed())
446 if (!static::checkRestictions($product))
450 if (!static::isExists())
455 $userFieldManager = Main\UserField\Internal\UserFieldHelper::getInstance()->getManager();
456 $request = Main\Context::getCurrent()->getRequest();
458 return $userFieldManager->GetEditFormHTML(
459 $config[
'FROM_FORM'],
460 $request->getPost($field[
'FIELD_NAME']) ??
'',
469 && static::checkRestictions($restrictions)
470 && static::isExists()
473 $userField = static::load();
474 if ($userField ===
null)
480 'entity' =>
'product',
481 'name' => $userField[
'FIELD_NAME'],
482 'originalName' => $userField[
'FIELD_NAME'],
483 'title' => $userField[
'EDIT_FORM_LABEL'] ?? $userField[
'FIELD_NAME'],
484 'hint' => $userField[
'HELP_MESSAGE'],
486 'required' => $userField[
'MANDATORY'] ===
'Y',
487 'multiple' => $userField[
'MULTIPLE'] ===
'Y',
488 'placeholders' =>
null,
489 'defaultValue' => $userField[
'SETTINGS'][
'DEFAULT_VALUE'] ??
'',
492 'showCode' =>
'true',
497 return static::getUiDescriptionInternal($description, $userField, $restrictions);
getFormRowFieldName(string $field)
static getUiDescriptionInternal(array $description, array $userField, array $restrictions)
static getAllowedProductTypeList()
static getTitleInternal()
static getAllowedOperations()
static array $allowedProductTypeList
static prepareValue(string $operation, array $productRow)
static checkAllowedProductType(int $type)
static getUserFieldBaseParam()
static getGroupActionRequest(ProductGroupAction $panel)
static getCommonError(string $errorCode)
static getOperationSelectFieldList(string $operation)
static getUserFieldName(string $id)
static array $allowedOperations
static checkAllowedOperation(string $operation)
static getGridActionConfig(ProductGroupAction $panel)
static renderAdminFormControl(array $field, array $product, array $config)
static afterLoadInternalModify(array $row)
static updateProductFormConfiguration()
static bool $bitrix24Include
static checkRestictions(array $restrictions)
static getUiDescription(array $restrictions)
static getGridAction(ProductGroupAction $panel)
static getMessages(string $file, array $messageIds)
static loadLanguageFile($file, $language=null, $normalize=true)
static getMessage($code, $replace=null, $language=null)
static getLabelsSelect(string $referenceName=null)
static getLabelsReference(string $referenceName=null, string $languageId=null)