Fix actions on Relationship search using Searchkit
authorjitendrapurohit <purohitjitend@gmail.com>
Sat, 24 Jun 2023 05:22:36 +0000 (10:52 +0530)
committerjitendrapurohit <purohitjitend@gmail.com>
Mon, 26 Jun 2023 06:17:15 +0000 (11:47 +0530)
ext/search_kit/Civi/Api4/Action/SearchDisplay/AbstractRunAction.php
ext/search_kit/Civi/Api4/Action/SearchDisplay/GetSearchTasks.php
ext/search_kit/ang/crmSearchTasks/crmSearchTasks.component.js

index 73dfc4c92ead87104ce8cf17903622181e75e180..d1e9b7490cfff6038d7fc0b26b8622ae93bcf9a7 100644 (file)
@@ -118,6 +118,9 @@ abstract class AbstractRunAction extends \Civi\Api4\Generic\AbstractAction {
   protected function formatResult(iterable $result): array {
     $rows = [];
     $keyName = CoreUtil::getIdFieldName($this->savedSearch['api_entity']);
+    if ($this->savedSearch['api_entity'] === 'RelationshipCache') {
+      $keyName = 'relationship_id';
+    }
     foreach ($result as $index => $record) {
       $data = $columns = [];
       foreach ($this->getSelectClause() as $key => $item) {
index 9676e096d33768db8c350686d4c6ac2073a15731..17b3b91c530b072e7718589183c0ff95127513c4 100644 (file)
@@ -34,7 +34,8 @@ class GetSearchTasks extends \Civi\Api4\Generic\AbstractAction {
    */
   public function _run(\Civi\Api4\Generic\Result $result) {
     // Adding checkPermissions filters out actions the user is not allowed to perform
-    $entity = Entity::get($this->checkPermissions)->addWhere('name', '=', $this->entity)
+    $entityName = ($this->entity === 'RelationshipCache') ? 'Relationship' : $this->entity;
+    $entity = Entity::get($this->checkPermissions)->addWhere('name', '=', $entityName)
       ->addSelect('name', 'title_plural')
       ->setChain([
         'actions' => ['$name', 'getActions', ['where' => [['name', 'IN', ['update', 'delete']]]], 'name'],
index b0f96effe0e8b4437e5179909f84446f9a079127..6b1d7d59bf6fc89d7370f0a0f31eeb06568d8362 100644 (file)
         return $scope.$eval('' + ctrl.ids.length + action.number);
       };
 
+      this.updateActionData = function() {
+        if (this.entity === 'RelationshipCache') {
+          this.entity = 'Relationship';
+          this.entityInfo.title = ts('Relationship');
+          this.entityInfo.title_plural = ts('Relationships');
+        }
+      };
+
       this.getActionTitle = function(action) {
         if (ctrl.isActionAllowed(action)) {
+          ctrl.updateActionData();
           return ctrl.ids.length ?
             ts('Perform action on %1 %2', {1: ctrl.ids.length, 2: ctrl.entityInfo[ctrl.ids.length === 1 ? 'title' : 'title_plural']}) :
             ts('Perform action on all %1', {1: ctrl.entityInfo.title_plural});
@@ -55,6 +64,9 @@
         if (!ctrl.isActionAllowed(action)) {
           return;
         }
+        // Update data specific to entity actions.
+        ctrl.updateActionData();
+
         var data = {
           ids: ctrl.ids,
           entity: ctrl.entity,