• Модуль: iblock
  • Путь к файлу: ~/bitrix/modules/iblock/lib/Controller/Property/Action/SaveAction.php
  • Класс: BitrixIblockControllerPropertyActionSaveAction
  • Вызов: SaveAction::run
public function run(int $propertyId, int $iblockId, array $fields): ?array
{
	if (!$this->checkWritePermissions($iblockId))
	{
		$this->errorCollection->setError(
			new Error(Loc::getMessage('IBLOCK_CONTROLLER_PROPERTY_ACTION_SAVE_ERROR_ACCESS_DENIED'))
		);

		return null;
	}

	$fields = $this->cleanEntityFields($fields);
	if (empty($fields))
	{
		$this->errorCollection->setError(
			new Error(Loc::getMessage('IBLOCK_CONTROLLER_PROPERTY_ACTION_SAVE_ERROR_EMPTY_REQUEST'))
		);

		return null;
	}

	$oldFields = null;
	if ($propertyId > 0)
	{
		$oldFields = $this->getPropertyFields($propertyId, $iblockId);
		if (!$oldFields)
		{
			$this->errorCollection->setError(
				new Error(Loc::getMessage('IBLOCK_CONTROLLER_PROPERTY_ACTION_SAVE_ERROR_NOT_FOUND'))
			);

			return null;
		}
	}

	$fields['IBLOCK_ID'] = $iblockId;
	$fields = $this->processUserTypeSettingsFields($fields, $oldFields);
	$fields = $this->processFeatureFields($fields, $oldFields);
	$fields = $this->processEnumFields($fields, $oldFields);

	if (CIBlock::GetArrayByID($iblockId, 'SECTION_PROPERTY') !== 'Y')
	{
		if (($fields['SMART_FILTER'] ?? 'N') === 'Y')
		{
			$iblock = new CIBlock;
			$iblock->Update($iblockId, ['SECTION_PROPERTY' => 'Y']);
			unset($iblock);
		}
	}

	$entity = new CIBlockProperty();
	if ($propertyId > 0)
	{
		$result = $entity->Update($propertyId, $fields);
	}
	else
	{
		$result = $entity->Add($fields);
		if ($result !== false)
		{
			$propertyId = (int)$result;
		}
	}

	if (!$result)
	{
		if ($entity->LAST_ERROR)
		{
			$this->errorCollection->setError(
				new Error($entity->LAST_ERROR)
			);
		}

		return null;
	}

	return [
		'id' => $propertyId,
	];
}