- Модуль: crm
- Путь к файлу: ~/bitrix/modules/crm/lib/controller/type.php
- Класс: Bitrix\Crm\Controller\Type
- Вызов: Type::updateAction
public function updateAction(\Bitrix\Crm\Model\Dynamic\Type $type, array $fields): ?array
{
$originalFields = $fields;
$fields = $this->convertKeysToUpper($fields);
$isNew = $type->getId() <= 0;
$restriction = RestrictionManager::getDynamicTypesLimitRestriction();
if ($isNew && $restriction->isCreateTypeRestricted())
{
$this->addError($restriction->getCreateTypeRestrictedError());
return null;
}
if (!$isNew && $restriction->isTypeSettingsRestricted($type->getEntityTypeId()))
{
$this->addError($restriction->getUpdateTypeRestrictedError());
return null;
}
unset($fields['ID']);
if (isset($fields['TITLE']))
{
$fields['TITLE'] = trim($fields['TITLE']);
}
if(!$isNew)
{
unset($fields['ENTITY_TYPE_ID'], $fields['NAME']);
}
foreach($fields as $name => $value)
{
if($type->entity->hasField($name))
{
$type->set($name, $value);
}
}
$result = $type->save();
if($result->isSuccess())
{
$this->saveConversionMap($type->getEntityTypeId(), $fields);
if ($type->getIsUseInUserfieldEnabled())
{
$this->saveLinkedUserFields(\CCrmOwnerType::ResolveName($type->getEntityTypeId()), $originalFields);
}
$relationsResult = $this->saveRelations($type->getEntityTypeId(), $fields);
if (!$relationsResult->isSuccess())
{
$this->addErrors($relationsResult->getErrors());
}
$customSectionsResult = $this->saveCustomSections($type, $fields);
if (!$customSectionsResult->isSuccess())
{
$this->addErrors($customSectionsResult->getErrors());
}
$result = $this->getAction($type);
if (is_array($result) && ($this->getScope() === static::SCOPE_AJAX))
{
$result['urlTemplates'] = Container::getInstance()->getRouter()->getTemplatesForJsRouter();
$result['isUrlChanged'] = $customSectionsResult->getData()['isCustomSectionChanged'] ?? false;
}
return $result;
}
$this->addErrors($result->getErrors());
return null;
}