From 36f45230de1ad164bfa1ed1cadef4130bef21080 Mon Sep 17 00:00:00 2001
From: Jaap Jansma <jaap@edeveloper.nl>
Date: Tue, 13 Oct 2015 11:48:32 +0200
Subject: [PATCH] added block for adding dynamic content to civirules

---
 CRM/Civirules/Action.php                      |  2 +-
 CRM/Civirules/Condition.php                   |  2 +-
 CRM/Civirules/Form/Rule.php                   | 24 +++++++++++++++++++
 .../FieldValueComparison.php                  |  2 +-
 .../Civirules/Form/RuleBlocks/RuleBlock.tpl   |  3 ++-
 5 files changed, 29 insertions(+), 4 deletions(-)

diff --git a/CRM/Civirules/Action.php b/CRM/Civirules/Action.php
index 96ec56d..aa27b86 100644
--- a/CRM/Civirules/Action.php
+++ b/CRM/Civirules/Action.php
@@ -118,7 +118,7 @@ abstract class CRM_Civirules_Action {
     $context['action_label'] = CRM_Civirules_BAO_Action::getActionLabelWithId($this->ruleAction['action_id']);
     $context['action_parameters'] = $this->userFriendlyConditionParams();
     $context['contact_id'] = $eventData ? $eventData->getContactId() : - 1;
-    $msg = "{action_label} ({rule_action_id}\r\n\r\n{message}\r\n\r\nRule: '{rule_title}' with id {rule_id}";
+    $msg = "{action_label} (ID: {rule_action_id})\r\n\r\n{message}\r\n\r\nRule: '{rule_title}' with id {rule_id}";
     if ($context['contact_id'] > 0) {
       $msg .= "\r\nFor contact: {contact_id}";
     }
diff --git a/CRM/Civirules/Condition.php b/CRM/Civirules/Condition.php
index 962384c..0ae377a 100644
--- a/CRM/Civirules/Condition.php
+++ b/CRM/Civirules/Condition.php
@@ -87,7 +87,7 @@ abstract class CRM_Civirules_Condition {
     $context['condition_label'] = CRM_Civirules_BAO_Condition::getConditionLabelWithId($this->ruleCondition['condition_id']);
     $context['condition_parameters'] = $this->userFriendlyConditionParams();
     $context['contact_id'] = $eventData ? $eventData->getContactId() : - 1;
-    $msg = "{condition_label} ({rule_condition_id}\r\n\r\n{message}\r\n\r\nRule: '{rule_title}' with id {rule_id}";
+    $msg = "{condition_label} (ID: {rule_condition_id})\r\n\r\n{message}\r\n\r\nRule: '{rule_title}' with id {rule_id}";
     if ($context['contact_id'] > 0) {
       $msg .= "\r\nFor contact: {contact_id}";
     }
diff --git a/CRM/Civirules/Form/Rule.php b/CRM/Civirules/Form/Rule.php
index a281e08..af58b54 100755
--- a/CRM/Civirules/Form/Rule.php
+++ b/CRM/Civirules/Form/Rule.php
@@ -17,6 +17,8 @@ class CRM_Civirules_Form_Rule extends CRM_Core_Form {
 
   protected $event;
 
+  protected $postRuleBlock = '';
+
   /**
    * @var CRM_Civirules_Event
    */
@@ -30,9 +32,31 @@ class CRM_Civirules_Form_Rule extends CRM_Core_Form {
   function buildQuickForm() {
     $this->setFormTitle();
     $this->createFormElements();
+    $this->assign('postRuleBlock', $this->postRuleBlock);
     parent::buildQuickForm();
   }
 
+  /**
+   * Post rule details are shown on the form just between the rule name and the
+   * linked trigger
+   *
+   * @return string
+   */
+  public function getPostRuleBlock() {
+    return $this->postRuleBlock;
+  }
+
+  /**
+   * Post rule details are shown on the form just between the rule name and the
+   * linked trigger
+   *
+   * @param $postRuleDetails
+   */
+  public function setPostRuleBlock($postRuleBlock) {
+    $this->postRuleBlock = $postRuleBlock;
+    $this->assign('postRuleBlock', $this->postRuleBlock);
+  }
+
   /**
    * Function to perform processing before displaying form (overrides parent function)
    * 
diff --git a/CRM/CivirulesConditions/FieldValueComparison.php b/CRM/CivirulesConditions/FieldValueComparison.php
index 4afe847..ad9bb6c 100644
--- a/CRM/CivirulesConditions/FieldValueComparison.php
+++ b/CRM/CivirulesConditions/FieldValueComparison.php
@@ -14,7 +14,7 @@ class CRM_CivirulesConditions_FieldValueComparison extends CRM_CivirulesConditio
   protected function getFieldValue(CRM_Civirules_EventData_EventData $eventData) {
     $entity = $this->conditionParams['entity'];
     $field = $this->conditionParams['field'];
-    
+
     $data = $eventData->getEntityData($entity);
     if (isset($data[$field])) {
       return $this->normalizeValue($data[$field]);
diff --git a/templates/CRM/Civirules/Form/RuleBlocks/RuleBlock.tpl b/templates/CRM/Civirules/Form/RuleBlocks/RuleBlock.tpl
index 90fb885..1d16336 100755
--- a/templates/CRM/Civirules/Form/RuleBlocks/RuleBlock.tpl
+++ b/templates/CRM/Civirules/Form/RuleBlocks/RuleBlock.tpl
@@ -20,5 +20,6 @@
     <div class="label">{$form.rule_created_contact.label}</div>
     <div class="content">{$form.rule_created_contact.value}</div>
     <div class="clear"></div>
-  </div>      
+  </div>
+  {$postRuleBlock}
 </div>
-- 
GitLab