From 77b4b813a1216e964f8e6d4631d1c2f6d5a927c1 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Tue, 19 Jul 2022 13:21:15 -0400 Subject: [PATCH] SearchKit - Allow html in columns This adds a column type 'html' and defaults rich-text fields to use that column type. Fixes dev/core#3723 --- .../SearchDisplay/AbstractRunAction.php | 7 +++++ ext/search_kit/ang/crmSearchAdmin.module.js | 2 +- .../crmSearchAdminDisplay.component.js | 13 +++++++- .../displays/colType/field.html | 8 ++++- .../crmSearchAdmin/displays/colType/html.html | 31 +++++++++++++++++++ .../ang/crmSearchDisplay/colType/html.html | 2 ++ 6 files changed, 60 insertions(+), 3 deletions(-) create mode 100644 ext/search_kit/ang/crmSearchAdmin/displays/colType/html.html create mode 100644 ext/search_kit/ang/crmSearchDisplay/colType/html.html diff --git a/ext/search_kit/Civi/Api4/Action/SearchDisplay/AbstractRunAction.php b/ext/search_kit/Civi/Api4/Action/SearchDisplay/AbstractRunAction.php index 59c209f818..5df9ef6d1e 100644 --- a/ext/search_kit/Civi/Api4/Action/SearchDisplay/AbstractRunAction.php +++ b/ext/search_kit/Civi/Api4/Action/SearchDisplay/AbstractRunAction.php @@ -206,6 +206,7 @@ abstract class AbstractRunAction extends \Civi\Api4\Generic\AbstractAction { $out = []; switch ($column['type']) { case 'field': + case 'html': $rawValue = $data[$column['key']] ?? NULL; if (!$this->hasValue($rawValue) && isset($column['empty_value'])) { $out['val'] = $this->replaceTokens($column['empty_value'], $data, 'view'); @@ -231,6 +232,12 @@ abstract class AbstractRunAction extends \Civi\Api4\Generic\AbstractAction { $out['edit'] = $edit; } } + if ($column['type'] === 'html') { + if (is_array($out['val'])) { + $out['val'] = implode(', ', $out['val']); + } + $out['val'] = \CRM_Utils_String::purifyHTML($out['val']); + } break; case 'image': diff --git a/ext/search_kit/ang/crmSearchAdmin.module.js b/ext/search_kit/ang/crmSearchAdmin.module.js index ddd9bc3350..729be45d64 100644 --- a/ext/search_kit/ang/crmSearchAdmin.module.js +++ b/ext/search_kit/ang/crmSearchAdmin.module.js @@ -317,7 +317,7 @@ var info = parseExpr(fieldExpr), field = (_.findWhere(info.args, {type: 'field'}) || {}).field || {}, values = _.merge({ - type: 'field', + type: field.input_type === 'RichTextEditor' ? 'html' : 'field', key: info.alias, dataType: (info.fn && info.fn.data_type) || field.data_type }, defaults); diff --git a/ext/search_kit/ang/crmSearchAdmin/crmSearchAdminDisplay.component.js b/ext/search_kit/ang/crmSearchAdmin/crmSearchAdminDisplay.component.js index 5956e2b3b6..88ce9ce155 100644 --- a/ext/search_kit/ang/crmSearchAdmin/crmSearchAdminDisplay.component.js +++ b/ext/search_kit/ang/crmSearchAdmin/crmSearchAdminDisplay.component.js @@ -126,7 +126,7 @@ }; this.getColLabel = function(col) { - if (col.type === 'field' || col.type === 'image') { + if (col.type === 'field' || col.type === 'image' || col.type === 'html') { return ctrl.getFieldLabel(col.key); } return ctrl.colTypes[col.type].label; @@ -162,6 +162,17 @@ } }; + this.toggleHtml = function(col) { + if (col.type === 'html') { + col.type = 'field'; + } else { + delete col.editable; + delete col.link; + delete col.icons; + col.type = 'html'; + } + }; + this.canBeImage = function(col) { var expr = ctrl.getExprFromSelect(col.key), info = searchMeta.parseExpr(expr); diff --git a/ext/search_kit/ang/crmSearchAdmin/displays/colType/field.html b/ext/search_kit/ang/crmSearchAdmin/displays/colType/field.html index e433778597..631a76d3e9 100644 --- a/ext/search_kit/ang/crmSearchAdmin/displays/colType/field.html +++ b/ext/search_kit/ang/crmSearchAdmin/displays/colType/field.html @@ -4,6 +4,12 @@ {{:: ts('Image') }} +
+ +