Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
newstemplate.php
1<?php
2
4
8
9Loc::loadMessages(__FILE__);
10
12{
13 protected const DEFAULT_BORDER_COLOR = '#468EE5';
14
15 protected string $title = '';
16
17 public function buildMessage(array $messageFields): array
18 {
19 $attach = new \CIMMessageParamAttach(0, static::DEFAULT_BORDER_COLOR);
20
21 $attach->SetDescription($this->buildDescriptionText());
22
23 $attach->AddGrid([
24 [
25 'DISPLAY' => 'LINE',
26 'NAME' => $this->title,
27 'VALUE' => $this->buildMessageText(),
28 ]
29 ]);
30
31 $messageFields['ATTACH'] = $attach;
32
33 return $messageFields;
34 }
35
36 protected function buildDescriptionText(): string
37 {
38 $text = mb_substr(\CBPHelper::convertBBtoText($this->title . ' ' . $this->messageText), 0, 200);
39 if (mb_strlen($text) === 200)
40 {
41 $text .= '...';
42 }
43
44 return $text;
45 }
46
47 protected function validate(): void
48 {
49 parent::validate();
50
51 if ($this->title === '')
52 {
53 $this->errors->setError(new Error(
54 Loc::getMessage('IM_BIZPROC_MESSAGE_NEWS_TEMPLATE_FIELD_NAME_MESSAGE_TITLE_ERROR')
55 ));
56 }
57 }
58
59 public function setFields(array $fields): self
60 {
61 parent::setFields($fields);
62
63 if (!empty($fields['MessageTitle']))
64 {
65 $this->title = trim(\CBPHelper::stringify($fields['MessageTitle']));
66 }
67
68 return $this;
69 }
70
71 public static function getFieldsMap(): array
72 {
73 return array_merge(
74 [
75 'MessageTitle' => [
76 'Name' => Loc::getMessage('IM_BIZPROC_MESSAGE_NEWS_TEMPLATE_FIELD_NAME_MESSAGE_TITLE'),
77 'FieldName' => 'title',
78 'Type' => FieldType::STRING,
79 'Required' => true,
80 'Multiple' => false,
81 ],
82 ],
83 parent::getFieldsMap(),
84 );
85 }
86}
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29