• Модуль: documentgenerator
  • Путь к файлу: ~/bitrix/modules/documentgenerator/lib/document.php
  • Класс: BitrixDocumentGeneratorDocument
  • Вызов: Document::process
protected function process(): Document
{
	// here we get actual number
	$this->getNumber(false);
	EventManager::getInstance()->send(new Event(Driver::MODULE_ID, 'onBeforeProcessDocument', ['document' => $this]));
	if(!$this->template)
	{
		$this->result->addError(new Error('Cant process document without template'));

		return $this;
	}
	if($this->template->isDeleted())
	{
		$this->result->addError(new Error('Cant process document on deleted template'));

		return $this;
	}
	if(!$this->template->getSourceType())
	{
		$this->result->addError(new Error('Cant process document on template without sourceType'));

		return $this;
	}
	DataProviderManager::getInstance()->setContext(Context::createFromDocument($this));
	$requiredFields = $this->checkFields();
	foreach($requiredFields as $placeholder => $field)
	{
		$this->result->addError(new Error('No value for required placeholder '.$placeholder));
	}
	if($this->result->isSuccess())
	{
		$values = $this->getValues($this->getFieldNames());
		if(!$this->isStampsEnabled())
		{
			foreach($this->fields as $placeholder => $field)
			{
				if(
					isset($field['TYPE']) &&
					$field['TYPE'] === DataProvider::FIELD_TYPE_STAMP
				)
				{
					$values[$placeholder] = ' ';
				}
			}
		}
		$bodyResult = $this->body->setValues($values)->setFields($this->fields)->process();
		if($bodyResult->isSuccess())
		{
			$resultData = ['BODY' => $this->body];
			$this->result->setData($resultData);
		}
		else
		{
			if ($bodyResult->getErrorCollection()->getErrorByCode('FILE_NOT_PROCESSABLE'))
			{
				$bodyResult->addError(new Error(Loc::getMessage('DOCUMENT_FILE_NOT_PROCESSABLE_ERROR')));
			}

			$this->result = $bodyResult;
		}
	}

	return $this;
}