UiFormConfiguration::setField

  1. Bitrix24 API (v. 23.675.0)
  2. catalog
  3. UiFormConfiguration
  4. setField
  • Модуль: catalog
  • Путь к файлу: ~/bitrix/modules/catalog/lib/update/uiformconfiguration.php
  • Класс: BitrixCatalogUpdateUiFormConfiguration
  • Вызов: UiFormConfiguration::setField
static function setField(array $formSettings, array $index, array $field, string $mode): array
{
	if (empty($formSettings) || !static::checkRowIndex($index))
	{
		return $formSettings;
	}

	$column = $index['COLUMN'];
	$list = $index['LIST'];
	$row = $index['ROW'];

	if (!isset($formSettings[$column]))
	{
		return $formSettings;
	}
	if (!isset($formSettings[$column]['elements'][$list]))
	{
		return $formSettings;
	}
	if (
		!isset($formSettings[$column]['elements'][$list]['elements'])
		|| !is_array($formSettings[$column]['elements'][$list]['elements'])
	)
	{
		return $formSettings;
	}

	switch ($mode)
	{
		case self::SET_MODE_FIRST:
			array_unshift(
				$formSettings[$column]['elements'][$list]['elements'],
				$field
			);
			break;
		case self::SET_MODE_LAST:
			$formSettings[$column]['elements'][$list]['elements'][] = $field;
			break;
		case self::SET_MODE_BEFORE:
			if (static::isRowExists($formSettings, $index))
			{
				if ($row === 0)
				{
					array_unshift(
						$formSettings[$column]['elements'][$list]['elements'],
						$field
					);
				}
				else
				{
					$before = array_slice($formSettings[$column]['elements'][$list]['elements'], 0, $row);
					$before[] = $field;
					$after = array_slice($formSettings[$column]['elements'][$list]['elements'], $row);
					$formSettings[$column]['elements'][$list]['elements'] = array_merge(
						$before,
						$after
					);
					unset($after, $before);
				}
			}
			break;
		case self::SET_MODE_AFTER:
			if (static::isRowExists($formSettings, $index))
			{
				if ($row === count($formSettings[$column]['elements'][$list]['elements']))
				{
					$formSettings[$column]['elements'][$list]['elements'][] = $field;
				}
				else
				{
					$before = array_slice($formSettings[$column]['elements'][$list]['elements'], 0, $row + 1);
					$before[] = $field;
					$after = array_slice($formSettings[$column]['elements'][$list]['elements'], $row + 1);
					$formSettings[$column]['elements'][$list]['elements'] = array_merge(
						$before,
						$after
					);
					unset($after, $before);
				}
			}
			break;
	}

	return $formSettings;
}

Добавить комментарий