Skip to content
Snippets Groups Projects
Commit 0643c2d9 authored by John Kirk's avatar John Kirk
Browse files

Added CiviRules Action Display Message. Allows a custom message to be...

Added CiviRules Action Display Message. Allows a custom message to be displayed to the user on conditions.
parent 1e6e4677
No related branches found
No related tags found
No related merge requests found
<?php
return array (
0 =>
array (
'name' => 'Civirules:Action.DisplayMessage',
'entity' => 'CiviRuleAction',
'params' =>
array (
'version' => 3,
'name' => 'DisplayMessage',
'label' => 'Shows a message to CiviCRM users.',
'class_name' => 'CRM_CivirulesActions_User_DisplayMessage',
'is_active' => 1
),
),
);
\ No newline at end of file
<?php
/**
* Class for CiviRules Display Message Action
*
* @author John Kirk (CiviFirst) <john@civifirst.com>
* @license AGPL-3.0
*/
class CRM_CivirulesActions_User_DisplayMessage extends CRM_Civirules_Action {
/**
* Method processAction to execute the action
*
* @param CRM_Civirules_TriggerData_TriggerData $triggerData
* @access public
*
*/
public function processAction(CRM_Civirules_TriggerData_TriggerData $triggerData) {
$action_params = $this->getActionParameters();
CRM_Core_Session::setStatus($action_params['message'], ts($action_params['title']), $action_params['type']);
}
/**
* Method to return the url for additional form processing for action
* and return false if none is needed
*
* @param int $ruleActionId
* @return bool
* @access public
*/
public function getExtraDataInputUrl($ruleActionId) {
return CRM_Utils_System::url('civicrm/civirule/form/action/display_message/', 'rule_action_id='.$ruleActionId);
}
}
\ No newline at end of file
<?php
/**
* Class for CiviRules Contribution Thank You Date Form
*
* @author John Kirk (CiviCooP) <john@civifirst.com>
* @license AGPL-3.0
*/
class CRM_CivirulesActions_User_Form_DisplayMessage extends CRM_CivirulesActions_Form_Form {
/**
* Overridden parent method to build the form
*
* @access public
*/
public function buildQuickForm() {
$this->add('hidden', 'rule_action_id');
$messageTypes = array('alert' => 'Alert', 'info' => 'Info', 'success' => 'Success', 'error' => 'Error',);
$this->add('text', 'title', ts('Message title: '));
$this->add('text', 'message', ts('Message: '));
$this->addRadio('type', ts('Type of message: '), $messageTypes);
$this->addButtons(array(
array('type' => 'next', 'name' => ts('Save'), 'isDefault' => TRUE,),
array('type' => 'cancel', 'name' => ts('Cancel'))));
}
/**
* Overridden parent method to set default values
*
* @return array $defaultValues
* @access public
*/
public function setDefaultValues() {
$defaultValues = parent::setDefaultValues();
$defaultValues['rule_action_id'] = $this->ruleActionId;
if (!empty($this->ruleAction->action_params)) {
$data = unserialize($this->ruleAction->action_params);
}
if (!empty($data['title'])) {
$defaultValues['title'] = $data['title'];
}
if (!empty($data['message'])) {
$defaultValues['message'] = $data['message'];
}
if (!empty($data['type'])) {
$defaultValues['type'] = $data['type'];
}
return $defaultValues;
}
/**
* Overridden parent method to process form data after submitting
*
* @access public
*/
public function postProcess() {
$data['title'] = $this->_submitValues['title'];
$data['message'] = $this->_submitValues['message'];
$data['type'] = $this->_submitValues['type'];
$this->ruleAction->action_params = serialize($data);
$this->ruleAction->save();
parent::postProcess();
}
}
\ No newline at end of file
<h3>{$ruleActionHeader}</h3>
<div class="crm-block crm-form-block crm-civirule-rule_action-block-message-display">
<div id="title-block" class="crm-section">
<div class="label">{$form.title.label}</div>
<div class="content">{$form.title.html}</div>
<div class="clear"></div>
</div>
<div id="message-block" class="crm-section">
<div class="label">{$form.message.label}</div>
<div class="content">{$form.message.html}</div>
<div class="clear"></div>
</div>
<div id="type-block" class="crm-section">
<div class="label">{$form.type.label}</div>
<div class="content">{$form.type.html}</div>
<div class="clear"></div>
</div>
</div>
<div class="crm-submit-buttons">
{include file="CRM/common/formButtons.tpl" location="bottom"}
</div>
\ No newline at end of file
......@@ -217,4 +217,11 @@
<access_arguments>access CiviCRM</access_arguments>
<access_arguments>administer CiviCRM</access_arguments>
</item>
<item>
<path>civicrm/civirule/form/action/display_message</path>
<page_callback>CRM_CivirulesActions_User_Form_DisplayMessage</page_callback>
<title>Display Message</title>
<access_arguments>access CiviCRM</access_arguments>
<access_arguments>administer CiviCRM</access_arguments>
</item>
</menu>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment