Use apiv4 on save
authoreileen <emcnaughton@wikimedia.org>
Wed, 15 Apr 2020 00:35:38 +0000 (12:35 +1200)
committereileen <emcnaughton@wikimedia.org>
Wed, 15 Apr 2020 00:35:38 +0000 (12:35 +1200)
CRM/Admin/Form/MessageTemplates.php

index cba4754dcd18a781ef0687c585aeec052b911cc5..11b564a3099319d52b840b66be8033e2bd65a5c5 100644 (file)
@@ -261,6 +261,10 @@ class CRM_Admin_Form_MessageTemplates extends CRM_Core_Form {
 
   /**
    * 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) {
@@ -303,12 +307,12 @@ class CRM_Admin_Form_MessageTemplates extends CRM_Core_Form {
         $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) {