Stage::processLogic

  1. Bitrix24 API (v. 23.675.0)
  2. crm
  3. Stage
  4. processLogic
  • Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/Field/Stage.php
  • Класс: Bitrix\Crm\Field\Stage
  • Вызов: Stage::processLogic
protected function processLogic(Item $item, Context $context = null): Result
{
	$result = new Result();

	$factory = Container::getInstance()->getFactory($item->getEntityTypeId());
	if (!$factory)
	{
		return $result->addError($this->getFactoryNotFoundError($item->getEntityTypeId()));
	}

	$isCategoryChanged = $factory->isCategoriesSupported() && $item->isChanged(Item::FIELD_NAME_CATEGORY_ID);

	if (!$isCategoryChanged && !$this->isValueChanged($item))
	{
		return $result;
	}

	if ($this->isCurrentStageIdValid($factory, $item))
	{
		return $result;
	}

	if (!$isCategoryChanged && !$item->isNew())
	{
		$result->addError($this->getValueNotValidError());

		return $result;
	}

	$newStageId = $this->pickFirstStageIdInCurrentCategory($factory, $item);

	if($newStageId)
	{
		$item->set($this->getName(), $newStageId);
	}
	else
	{
		$result->addError(new Error('Stage in new category is not found'));
	}

	return $result;
}

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