- Модуль: landing
- Путь к файлу: ~/bitrix/modules/landing/lib/internals/folder.php
- Класс: BitrixLandingInternalsFolderTable
- Вызов: FolderTable::prepareChange
static function prepareChange(EntityEvent $event, string $actionType): EntityEventResult
{
$result = new EntityEventResult();
$primary = $event->getParameter('primary');
$fields = $event->getParameter('fields');
$modifyFields = [];
// check that index landing is exists in folder's site
/*if ($fields['INDEX_ID'] ?? 0)
{
if (!array_key_exists('SITE_ID', $fields))
{
$fields['SITE_ID'] = self::getList([
'select' => [
'SITE_ID'
],
'filter' => [
'ID' => $primary['ID'] ?? 0
]
])->fetch()['SITE_ID'] ?? 0;
}
$res = LandingTable::getList([
'select' => [
'ID'
],
'filter' => [
'SITE_ID' => $fields['SITE_ID'],
'ID' => $fields['INDEX_ID'],
'FOLDER_ID' => $primary['ID'] ?? 0
]
]);
if (!$res->fetch())
{
$result->setErrors([
new EntityEntityError(
Loc::getMessage('LANDING_TABLE_ERROR_FOLDER_INDEX_OUT_OF_SITE'),
'FOLDER_INDEX_OUT_OF_SITE'
)
]);
return $result;
}
}*/
// translit the code from title
if (
$actionType == self::ACTION_TYPE_ADD && array_key_exists('TITLE', $fields) &&
(!array_key_exists('CODE', $fields) || trim($fields['CODE']) == '')
)
{
$fields['CODE'] = CUtil::translit(
trim($fields['TITLE']),
LANGUAGE_ID,
[
'replace_space' => '',
'replace_other' => ''
]
);
if (!$fields['CODE'])
{
$fields['CODE'] = Manager::getRandomString(12);
}
$modifyFields['CODE'] = $fields['CODE'];
}
// for update always we need the code
if (isset($primary['ID']) && !array_key_exists('CODE', $fields))
{
$res = self::getList([
'select' => [
'CODE'
],
'filter' => [
'ID' => $primary['ID']
]
]);
if ($row = $res->fetch())
{
$fields['CODE'] = $row['CODE'];
}
}
// check unique folder
if (
array_key_exists('CODE', $fields) &&
array_key_exists('SITE_ID', $fields) &&
BitrixLandingLanding::isCheckUniqueAddress()
)
{
$filter = [
'=CODE' => $fields['CODE'],
'SITE_ID' => $fields['SITE_ID'],
'PARENT_ID' => $fields['PARENT_ID'] ?? null
];
if (isset($primary['ID']))
{
$filter['!ID'] = $primary['ID'];
}
$res = self::getList([
'select' => [
'ID'
],
'filter' => $filter
]);
if ($res->fetch())
{
$result->setErrors([
new EntityEntityError(
Loc::getMessage('LANDING_TABLE_ERROR_FOLDER_IS_NOT_UNIQUE'),
'FOLDER_IS_NOT_UNIQUE'
)
]);
return $result;
}
}
// check correct folder path
if (array_key_exists('CODE', $fields))
{
if (mb_strpos($fields['CODE'], '/') !== false)
{
$result->setErrors([
new EntityEntityError(
Loc::getMessage('LANDING_TABLE_ERROR_FOLDER_SLASH_IS_NOT_ALLOWED'),
'SLASH_IS_NOT_ALLOWED'
)
]);
return $result;
}
}
$result->modifyFields($modifyFields);
return $result;
}