Created
May 26, 2021 06:39
-
-
Save Isa3v/918044ae9aa5403a44c93346f65d581c to your computer and use it in GitHub Desktop.
Пользовательское поле (свойство раздела) Bitrix - строка с описанием
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// $eventManager->addEventHandler("main", "OnUserTypeBuildList", ['PropStringDesc', "getUserTypeDescription"]); | |
class PropStringDesc extends \CUserTypeString | |
{ | |
public function getUserTypeDescription() | |
{ | |
return [ | |
'USER_TYPE_ID' => 'PropStringDesc', | |
'CLASS_NAME' => __CLASS__, | |
'DESCRIPTION' => 'Строка с описанием', | |
'BASE_TYPE' => 'string' | |
]; | |
} | |
/** | |
* Вывод в админке | |
* | |
* @param [type] $arUserField | |
* @param [type] $arHtmlControl | |
* @return void | |
*/ | |
public function getEditFormHTML($arUserField, $arHtmlControl) | |
{ | |
return ' | |
<table border="0" cellspacing="0" cellpadding="0" width="100%" class="internal"> | |
<tbody> | |
<tr class="heading"> | |
<td>Строка</td> | |
<td>Описание</td> | |
</tr> | |
<tr> | |
<td align="center"> | |
<input type="text" name="'.$arHtmlControl["NAME"].'[NAME]" value="'.$arHtmlControl['VALUE']['NAME'].'" /></td> | |
<td align="center"> | |
<input type="text" name="'.$arHtmlControl["NAME"].'[DESC]" value="'.$arHtmlControl['VALUE']['DESC'].'" /> | |
</td> | |
</tr> | |
</tbody> | |
</table> | |
'; | |
return $html; | |
} | |
/** | |
* Сохранение в БД | |
* | |
* @param [type] $arUserField | |
* @param [type] $value | |
* @return string | |
*/ | |
public function OnBeforeSave($arUserField, $value): string | |
{ | |
$value = \Bitrix\Main\Web\Json::encode($value); | |
return $value; | |
} | |
/** | |
* Извлечение из БД | |
* | |
* @param [type] $arProperty | |
* @param [type] $arValue | |
* @return array | |
*/ | |
public function onAfterFetch($arProperty, $arValue): array | |
{ | |
if (!empty($arValue["VALUE"])) { | |
$arValue = \Bitrix\Main\Web\Json::decode(html_entity_decode($arValue["VALUE"])); | |
} | |
return $arValue; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment