- Модуль: crm
- Путь к файлу: ~/bitrix/modules/crm/lib/controller/item.php
- Класс: Bitrix\Crm\Controller\Item
- Вызов: Item::getEditorAction
public function getEditorAction(
int $entityTypeId,
int $id,
string $guid = null,
string $configId = null,
int $categoryId = null,
string $stageId = null,
string $viewMode = null,
array $params = []
): ?Component
{
$factory = $this->getFactory($entityTypeId);
if (!$factory)
{
return null;
}
$componentName = $params['componentName']
?? Container::getInstance()->getRouter()->getItemDetailComponentName($entityTypeId);
if (!$componentName)
{
$this->addError(new Error('Component for entity ' . $entityTypeId . ' not found'));
return null;
}
$componentClassName = \CBitrixComponent::includeComponentClass($componentName);
$component = new $componentClassName;
if (!($component instanceof FactoryBased))
{
$this->addError(new Error('Component for entity ' . $entityTypeId . ' not found'));
return null;
}
$component->initComponent($componentName);
$component->arParams = [
'ENTITY_TYPE_ID' => $entityTypeId,
'ENTITY_ID' => $id,
'categoryId' => $categoryId,
'skipFields' => [$factory->getEntityFieldNameByMap(\Bitrix\Crm\Item::FIELD_NAME_STAGE_ID)],
];
$component->init();
if (!empty($component->getErrors()))
{
$this->addErrors($component->getErrors());
return null;
}
$component->initializeEditorAdapter();
$editorConfig = $component->getEditorConfig();
$editorConfig['ENTITY_CONFIG'] = $component->getInlineEditorEntityConfig();
if ($stageId)
{
$editorConfig['CONTEXT']['STAGE_ID'] = $stageId;
}
// In the deadlines mode we have to set actual_date and first stage for new entity
if (
$viewMode === ViewMode::MODE_DEADLINES &&
Deadlines\DeadlinesStageManager::isEntitySupportDeadlines($entityTypeId)
)
{
$fieldName = Deadlines\DeadlinesStageManager::dateFieldByEntityType($entityTypeId);
$deadLinePeriods = new Deadlines\DatePeriods();
$actualDate = $deadLinePeriods->calculateDateByStage($stageId);
$stages = $factory->getStages()->getStatusIdList();
$editorConfig['ENTITY_DATA'][$fieldName] = $actualDate;
$editorConfig['CONTEXT']['STAGE_ID'] = $stages[0] ?? null ;
$editorConfig['CONTEXT']['VIEW_MODE'] = ViewMode::MODE_DEADLINES;
$editorConfig['CONTEXT']['DEADLINE_STAGE'] = $stageId;
}
$forceDefaultConfig = $params['forceDefaultConfig'] ?? 'N';
$editorConfig['FORCE_DEFAULT_CONFIG'] = ($forceDefaultConfig === 'Y');
$editorConfig['IS_EMBEDDED'] = ($params['IS_EMBEDDED'] ?? 'Y') === 'Y';
$editorConfig['GUID'] = $guid ?? $editorConfig['GUID'];
$editorConfig['CONFIG_ID'] = $configId ?? $editorConfig['CONFIG_ID'];
$enableSingleSectionCombining = ($params['enableSingleSectionCombining'] ?? 'Y') === 'Y';
$editorConfig['COMPONENT_AJAX_DATA']['SIGNED_PARAMETERS'] = ParameterSigner::signParameters(
$component->getName(),
$component->arParams
);
$disabledOptions = [
'ENABLE_SECTION_EDIT',
'ENABLE_SECTION_CREATION',
'ENABLE_SECTION_DRAG_DROP',
'ENABLE_FIELD_DRAG_DROP',
'ENABLE_MODE_TOGGLE',
'ENABLE_TOOL_PANEL',
'ENABLE_BOTTOM_PANEL',
'ENABLE_USER_FIELD_CREATION',
'ENABLE_PAGE_TITLE_CONTROLS',
'ENABLE_FIELDS_CONTEXT_MENU',
'ENABLE_PERSONAL_CONFIGURATION_UPDATE',
'ENABLE_COMMON_CONFIGURATION_UPDATE',
'ENABLE_CONFIG_SCOPE_TOGGLE',
'ENABLE_SETTINGS_FOR_ALL',
'ENABLE_REQUIRED_FIELDS_INJECTION',
];
foreach ($disabledOptions as $option)
{
$editorConfig[$option] = $params[$option] ?? false;
if ($editorConfig[$option] === 'true')
{
$editorConfig[$option] = true;
}
else if ($editorConfig[$option] === 'false')
{
$editorConfig[$option] = false;
}
}
$editorConfig['ENABLE_USER_FIELD_MANDATORY_CONTROL'] = true;
$editorConfig['ENABLE_AJAX_FORM'] = true;
$editorConfig['INITIAL_MODE'] = 'edit';
$requiredFields = array_unique($params['requiredFields'] ?? []);
$entityConfig = $editorConfig['ENTITY_CONFIG'];
if (!empty($requiredFields))
{
$entityConfig = [
[
'elements' => [],
],
];
foreach ($requiredFields as $field)
{
$entityConfig[0]['elements'][] = ['name' => $field];
}
$editorConfig['ENTITY_FIELDS'] = EditorAdapter::markFieldsAsRequired($editorConfig['ENTITY_FIELDS'], $requiredFields);
}
if ($enableSingleSectionCombining)
{
$editorConfig['ENTITY_CONFIG'] = EditorAdapter::combineConfigIntoOneSection($entityConfig, $params['title'] ?? '');
}
return new Component('bitrix:crm.entity.editor', '', $editorConfig);
}