From 33b33abc2bf28811d2b36ecc660bb3ddc0f491b0 Mon Sep 17 00:00:00 2001 From: eileen Date: Wed, 15 Apr 2020 12:17:33 +1200 Subject: [PATCH] [REF] MessageTemplate form code level improvements I'm looking to cleanup this form to use the apiv4 (I'd rather got the extra step & switch it to an afform but that seems like too big a leap). This switches the loading to use apiv4. Note that 1) I decided that it doesn't make sense to setCheckPermissions = FALSE - I think the form should not be availble to non-permissioned users (& perhaps a hook might like to play a role here). 2) I removed the inheritence from the parent which seemed to do 3 things - added admin.css - none of the classes seemed to apply - added iconpicker - didn't seem to apply - loaded the defaults - which this change does on the form more succinctly --- CRM/Admin/Form/MessageTemplates.php | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/CRM/Admin/Form/MessageTemplates.php b/CRM/Admin/Form/MessageTemplates.php index b1bb341972..cba4754dcd 100644 --- a/CRM/Admin/Form/MessageTemplates.php +++ b/CRM/Admin/Form/MessageTemplates.php @@ -9,6 +9,8 @@ +--------------------------------------------------------------------+ */ +use Civi\Api4\MessageTemplate; + /** * * @package CRM @@ -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 @@ -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(); + } } /** -- 2.25.1