Skip to content

EspoCRM – Open Source CRM Application

KB Article plain

Yurii011fae642db5
diff --git a/application/Espo/Core/Upgrades/Migrations/V10_1/AfterUpgrade.php b/application/Espo/Core/Upgrades/Migrations/V10_1/AfterUpgrade.php
index 5c889f027e..59b076eb5f 100644
--- a/application/Espo/Core/Upgrades/Migrations/V10_1/AfterUpgrade.php
+++ b/application/Espo/Core/Upgrades/Migrations/V10_1/AfterUpgrade.php
@@ -37,8 +37,10 @@ use Espo\Entities\LeadCapture;
use Espo\Entities\Portal;
use Espo\Entities\Preferences;
use Espo\Entities\User;
+use Espo\Modules\Crm\Entities\KnowledgeBaseArticle;
use Espo\ORM\Entity;
use Espo\ORM\EntityManager;
+use Espo\ORM\Query\UpdateBuilder;
class AfterUpgrade implements Script
{
@@ -57,6 +59,7 @@ class AfterUpgrade implements Script
$this->updatePreferences();
$this->updatePortals();
$this->updateLeadCaptures();
+ $this->updateKBArticles();
}
private function updateConfig(): void
@@ -144,4 +147,16 @@ class AfterUpgrade implements Script
return (object) $themeParams;
}
+
+ private function updateKBArticles(): void
+ {
+ $query = UpdateBuilder::create()
+ ->in(KnowledgeBaseArticle::ENTITY_TYPE)
+ ->set([
+ 'isHtml' => true,
+ ])
+ ->build();
+
+ $this->entityManager->getQueryExecutor()->execute($query);
+ }
}
diff --git a/application/Espo/Modules/Crm/Entities/KnowledgeBaseArticle.php b/application/Espo/Modules/Crm/Entities/KnowledgeBaseArticle.php
index a1a82b47ed..3b67cbc74c 100644
--- a/application/Espo/Modules/Crm/Entities/KnowledgeBaseArticle.php
+++ b/application/Espo/Modules/Crm/Entities/KnowledgeBaseArticle.php
@@ -44,6 +44,13 @@ class KnowledgeBaseArticle extends Entity
public const STATUS_PUBLISHED = 'Published';
public const STATUS_ARCHIVED = 'Archived';
+ /** @since 10.1.0 */
+ public const string FIELD_IS_HTML = 'isHtml';
+ /** @since 10.1.0 */
+ public const string FIELD_BODY = 'body';
+ /** @since 10.1.0 */
+ public const string FIELD_BODY_PLAIN = 'bodyPlain';
+
public function getName(): ?string
{
return $this->get(Field::NAME);
@@ -127,4 +134,10 @@ class KnowledgeBaseArticle extends Entity
{
return $this->set('body', $body);
}
+
+ /** @since 10.1.0 */
+ public function isHtml(): bool
+ {
+ return $this->get(self::FIELD_IS_HTML);
+ }
}
diff --git a/application/Espo/Modules/Crm/Hooks/KnowledgeBaseArticle/SetBodyPlain.php b/application/Espo/Modules/Crm/Hooks/KnowledgeBaseArticle/SetBodyPlain.php
index 32265ffa0b..1c804c68b7 100644
--- a/application/Espo/Modules/Crm/Hooks/KnowledgeBaseArticle/SetBodyPlain.php
+++ b/application/Espo/Modules/Crm/Hooks/KnowledgeBaseArticle/SetBodyPlain.php
@@ -40,18 +40,22 @@ use Espo\Tools\Email\Util as EmailUtil;
*/
class SetBodyPlain implements BeforeSave
{
- private const ATTR_BODY = 'body';
- private const ATTR_BODY_PLAIN = 'bodyPlain';
-
public function beforeSave(Entity $entity, SaveOptions $options): void
{
- if (!$entity->isAttributeChanged(self::ATTR_BODY)) {
+ if (
+ !$entity->isAttributeChanged(KnowledgeBaseArticle::FIELD_BODY) &&
+ !$entity->isAttributeChanged(KnowledgeBaseArticle::FIELD_IS_HTML)
+ ) {
return;
}
- $bodyPlain = $this->stripHtml($entity->getBody());
+ if ($entity->isHtml()) {
+ $bodyPlain = $this->stripHtml($entity->getBody());
+ } else {
+ $bodyPlain = $entity->getBody();
+ }
- $entity->set(self::ATTR_BODY_PLAIN, $bodyPlain);
+ $entity->set(KnowledgeBaseArticle::FIELD_BODY_PLAIN, $bodyPlain);
}
private function stripHtml(?string $body): ?string
diff --git a/application/Espo/Modules/Crm/Resources/i18n/en_US/KnowledgeBaseArticle.json b/application/Espo/Modules/Crm/Resources/i18n/en_US/KnowledgeBaseArticle.json
index 2fbf1e8bad..e498854a83 100644
--- a/application/Espo/Modules/Crm/Resources/i18n/en_US/KnowledgeBaseArticle.json
+++ b/application/Espo/Modules/Crm/Resources/i18n/en_US/KnowledgeBaseArticle.json
@@ -20,7 +20,8 @@
"categories": "Categories",
"language": "Language",
"portals": "Portals",
- "bodyPlain": "Body Plain"
+ "bodyPlain": "Body Plain",
+ "isHtml": "HTML"
},
"links": {
"cases": "Cases",
diff --git a/application/Espo/Modules/Crm/Resources/layouts/KnowledgeBaseArticle/detail.json b/application/Espo/Modules/Crm/Resources/layouts/KnowledgeBaseArticle/detail.json
index b2281d7432..899b98ff79 100644
--- a/application/Espo/Modules/Crm/Resources/layouts/KnowledgeBaseArticle/detail.json
+++ b/application/Espo/Modules/Crm/Resources/layouts/KnowledgeBaseArticle/detail.json
@@ -10,7 +10,7 @@
{
"rows": [
[{"name": "body"}],
- [{"name": "attachments"}]
+ [{"name": "attachments"}, {"name": "isHtml"}]
]
}
]
diff --git a/application/Espo/Modules/Crm/Resources/layouts/KnowledgeBaseArticle/detailSmall.json b/application/Espo/Modules/Crm/Resources/layouts/KnowledgeBaseArticle/detailSmall.json
index 5008468327..2f5c9127e6 100644
--- a/application/Espo/Modules/Crm/Resources/layouts/KnowledgeBaseArticle/detailSmall.json
+++ b/application/Espo/Modules/Crm/Resources/layouts/KnowledgeBaseArticle/detailSmall.json
@@ -9,7 +9,7 @@
{
"rows": [
[{"name": "body"}],
- [{"name": "attachments"}]
+ [{"name": "attachments"}, {"name": "isHtml"}]
]
}
]
diff --git a/application/Espo/Modules/Crm/Resources/layouts/KnowledgeBaseArticle/filters.json b/application/Espo/Modules/Crm/Resources/layouts/KnowledgeBaseArticle/filters.json
index 389717fd0c..0939a64842 100644
--- a/application/Espo/Modules/Crm/Resources/layouts/KnowledgeBaseArticle/filters.json
+++ b/application/Espo/Modules/Crm/Resources/layouts/KnowledgeBaseArticle/filters.json
@@ -8,6 +8,7 @@
"status",
"portals",
"publishDate",
+ "isHtml",
"assignedUser",
"teams"
]
diff --git a/application/Espo/Modules/Crm/Resources/metadata/entityDefs/KnowledgeBaseArticle.json b/application/Espo/Modules/Crm/Resources/metadata/entityDefs/KnowledgeBaseArticle.json
index 3fc329330d..22fd8056b0 100644
--- a/application/Espo/Modules/Crm/Resources/metadata/entityDefs/KnowledgeBaseArticle.json
+++ b/application/Espo/Modules/Crm/Resources/metadata/entityDefs/KnowledgeBaseArticle.json
@@ -108,13 +108,39 @@
"type": "attachmentMultiple"
},
"body": {
- "type": "wysiwyg"
+ "type": "wysiwyg",
+ "view": "modules/crm/views/knowledge-base-article/fields/body",
+ "attachmentField": "attachments",
+ "audited": true,
+ "fieldManagerParamList": [
+ "required",
+ "audited",
+ "height",
+ "minHeight",
+ "useIframe",
+ "maxLength",
+ "readOnly",
+ "tooltipText"
+ ]
},
"bodyPlain": {
"type": "text",
"readOnly": true,
"directUpdateDisabled": true,
+ "dynamicLogicDisabled": true,
"fieldManagerParamList": []
+ },
+ "isHtml": {
+ "type": "bool",
+ "default": false,
+ "audited": true,
+ "fieldManagerParamList": [
+ "default",
+ "tooltipText"
+ ],
+ "inlineEditDisabled": true,
+ "layoutDefaultSidePanelDisabled": true,
+ "massUpdateDisabled": true
}
},
"links": {
diff --git a/client/modules/crm/src/views/knowledge-base-article/fields/body.ts b/client/modules/crm/src/views/knowledge-base-article/fields/body.ts
new file mode 100644
index 0000000000..800c4b100e
--- /dev/null
+++ b/client/modules/crm/src/views/knowledge-base-article/fields/body.ts
@@ -0,0 +1,34 @@
+/************************************************************************
+ * This file is part of EspoCRM.
+ *
+ * EspoCRM – Open Source CRM application.
+ * Copyright (C) 2014-2026 EspoCRM, Inc.
+ * Website: https://www.espocrm.com
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ * The interactive user interfaces in modified source and object code versions
+ * of this program must display Appropriate Legal Notices, as required under
+ * Section 5 of the GNU Affero General Public License version 3.
+ *
+ * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
+ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
+ ************************************************************************/
+
+import WysiwygFieldView from 'views/fields/wysiwyg';
+
+export default class KnowledgeBaseArticleBodyFieldView extends WysiwygFieldView {
+
+ protected hasBodyPlainField: boolean = true
+}