- Модуль: crmmobile
- Путь к файлу: ~/bitrix/modules/crmmobile/lib/Controller/EntityDetails.php
- Класс: BitrixCrmMobileControllerEntityDetails
- Вызов: EntityDetails::addInternalAction
public function addInternalAction(
Factory $factory,
Item $entity,
array $data,
?int $categoryId = null,
bool $isCreationFromSelector = false,
?array $client = []
): ?int
{
// setCompatibleData overrides all previous filled fields, so we need to fill category explicitly
if ($categoryId !== null && $entity->isCategoriesSupported())
{
$data[Item::FIELD_NAME_CATEGORY_ID] = $categoryId;
}
$entityTypeName = $factory->getEntityName();
//When converting from a lead, you do not need to create a link between the elements, because it happens in crm.lead.show
$isNeedAttachConversionItem = true;
$conversionWizard = $this->getConversionWizard();
if ($conversionWizard !== null)
{
$isNeedAttachConversionItem = $this->prepareConversionData($conversionWizard, $entityTypeName, $data);
if (!isset($data[Item::FIELD_NAME_PRODUCTS]) || !is_array($data[Item::FIELD_NAME_PRODUCTS]))
{
$this->prepareConversionItemProducts($entity);
}
}
if (!empty($client['company']) && $entity->getEntityTypeId() === CCrmOwnerType::Contact)
{
$data['COMPANY_IDS'] = $client['company'];
}
if ($this->isCopyMode())
{
$this->prepareCopyData($factory, $entity, $data);
}
$command = new SaveEntityCommand($factory, $entity, $data);
$result = $command->execute();
if (!$result->isSuccess())
{
$errors = $this->markErrorsAsPublic($result->getErrors());
$this->addErrors($errors);
return null;
}
$entityId = (int)$result->getData()['ID'];
if ($conversionWizard !== null)
{
if ($isNeedAttachConversionItem)
{
$conversionWizard->attachNewlyCreatedEntity($entityTypeName, $entityId);
}
$this->clearConversionParams();
}
if ($isCreationFromSelector && $entityId)
{
$this->saveEntityInSelectorRecent($factory, $entityId);
}
return $entityId;
}