Skip to content

Commit

Permalink
Merge pull request #17073 from eileenmcnaughton/msg_template
Browse files Browse the repository at this point in the history
Add MessageTemplate api to v4
  • Loading branch information
seamuslee001 authored Apr 17, 2020
2 parents 35fdd6a + c74478c commit 9a0c2cd
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 11 deletions.
34 changes: 23 additions & 11 deletions CRM/Admin/Form/MessageTemplates.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
+--------------------------------------------------------------------+
*/

use Civi\Api4\MessageTemplate;

/**
*
* @package CRM
Expand All @@ -19,7 +21,7 @@
* This class generates form components for Message templates
* used by membership, contributions, event registrations, etc.
*/
class CRM_Admin_Form_MessageTemplates extends CRM_Admin_Form {
class CRM_Admin_Form_MessageTemplates extends CRM_Core_Form {
/**
* which (and whether) mailing workflow this template belongs to
* @var int
Expand All @@ -28,20 +30,26 @@ class CRM_Admin_Form_MessageTemplates extends CRM_Admin_Form {

/**
* Is document file is already loaded as default value?
*
* @var bool
*/
protected $_is_document = FALSE;

/**
* PreProcess form - load existing values.
*
* @throws \API_Exception
* @throws \CRM_Core_Exception
* @throws \Civi\API\Exception\UnauthorizedException
*/
public function preProcess() {
$this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
$this->_action = CRM_Utils_Request::retrieve('action', 'String',
$this, FALSE, 'add'
);
$this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'add');
$this->assign('action', $this->_action);

$this->_BAOName = 'CRM_Core_BAO_MessageTemplate';
$this->set('BAOName', $this->_BAOName);
parent::preProcess();
$this->_values = [];
if ($this->_id) {
$this->_values = (array) MessageTemplate::get()->addWhere('id', '=', $this->_id)->setSelect(['*'])->execute()->first();
}
}

/**
Expand Down Expand Up @@ -253,6 +261,10 @@ public static function formRule($params, $files, $self) {

/**
* Process the form submission.
*
* @throws \API_Exception
* @throws \CRM_Core_Exception
* @throws \Civi\API\Exception\UnauthorizedException
*/
public function postProcess() {
if ($this->_action & CRM_Core_Action::DELETE) {
Expand Down Expand Up @@ -295,12 +307,12 @@ public function postProcess() {
$params['is_active'] = TRUE;
}

$messageTemplate = CRM_Core_BAO_MessageTemplate::add($params);
CRM_Core_Session::setStatus(ts('The Message Template \'%1\' has been saved.', [1 => $messageTemplate->msg_title]), ts('Saved'), 'success');
$messageTemplate = MessageTemplate::save()->setDefaults($params)->setRecords([['id' => $this->_id]])->execute()->first();
CRM_Core_Session::setStatus(ts('The Message Template \'%1\' has been saved.', [1 => $messageTemplate['msg_title']]), ts('Saved'), 'success');

if (isset($this->_submitValues['_qf_MessageTemplates_upload'])) {
// Save button was pressed
CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/messageTemplates/add', "action=update&id={$messageTemplate->id}&reset=1"));
CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/messageTemplates/add', "action=update&id={$messageTemplate['id']}&reset=1"));
}
// Save and done button was pressed
if ($this->_workflow_id) {
Expand Down
30 changes: 30 additions & 0 deletions Civi/Api4/MessageTemplate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

/*
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC. All rights reserved. |
| |
| This work is published under the GNU AGPLv3 license with some |
| permitted exceptions and without any warranty. For full license |
| and copyright information, see https://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/

/**
*
* @package CRM
* @copyright CiviCRM LLC https://civicrm.org/licensing
*/

namespace Civi\Api4;

/**
* MsgTemplate entity.
*
* This is a collection of MsgTemplate, for reuse in import, export, etc.
*
* @package Civi\Api4
*/
class MessageTemplate extends Generic\DAOEntity {

}

0 comments on commit 9a0c2cd

Please sign in to comment.