From: eileen Date: Mon, 28 Oct 2019 01:57:27 +0000 (+1300) Subject: Partial conversion of Payment form to use the EntityFormTrait & add title X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=833764691ef21020d2c25176cea7dbb9c98cfec1;p=civicrm-core.git Partial conversion of Payment form to use the EntityFormTrait & add title This partially converts the form to the new EntityForm format --- diff --git a/CRM/Admin/Form/PaymentProcessor.php b/CRM/Admin/Form/PaymentProcessor.php index d8b3293955..c997a46e1f 100644 --- a/CRM/Admin/Form/PaymentProcessor.php +++ b/CRM/Admin/Form/PaymentProcessor.php @@ -35,11 +35,7 @@ * This class generates form components for Payment Processor. */ class CRM_Admin_Form_PaymentProcessor extends CRM_Admin_Form { - protected $_id = NULL; - - protected $_testID = NULL; - - protected $_fields = NULL; + use CRM_Core_Form_EntityFormTrait; protected $_paymentProcessorDAO; @@ -49,6 +45,49 @@ class CRM_Admin_Form_PaymentProcessor extends CRM_Admin_Form { */ protected $_paymentProcessorType; + /** + * Fields for the entity to be assigned to the template. + * + * Fields may have keys + * - name (required to show in tpl from the array) + * - description (optional, will appear below the field) + * Auto-added by setEntityFieldsMetadata unless specified here (use description => '' to hide) + * - not-auto-addable - this class will not attempt to add the field using addField. + * (this will be automatically set if the field does not have html in it's metadata + * or is not a core field on the form's entity). + * - help (option) add help to the field - e.g ['id' => 'id-source', 'file' => 'CRM/Contact/Form/Contact']] + * - template - use a field specific template to render this field + * - required + * - is_freeze (field should be frozen). + * + * @var array + */ + protected $entityFields = []; + + /** + * Set entity fields to be assigned to the form. + */ + protected function setEntityFields() { + $this->entityFields = [ + 'payment_processor_type_id' => [ + 'name' => 'payment_processor_type_id', + 'required' => TRUE, + ], + 'name' => [ + 'name' => 'name', + 'required' => TRUE, + ], + 'title' => [ + 'name' => 'title', + ], + 'description' => [ + 'name' => 'description', + ], + ]; + + $this->setEntityFieldsMetadata(); + } + /** * Get the name of the base entity being edited. * @@ -58,6 +97,15 @@ class CRM_Admin_Form_PaymentProcessor extends CRM_Admin_Form { return 'PaymentProcessor'; } + /** + * Set the delete message. + * + * We do this from the constructor in order to do a translation. + */ + public function setDeleteMessage() { + $this->deleteMessage = ts('Deleting this Payment Processor may result in some transaction pages being rendered inactive.') . ' ' . ts('Do you want to continue?'); + } + public function preProcess() { parent::preProcess(); @@ -171,18 +219,14 @@ class CRM_Admin_Form_PaymentProcessor extends CRM_Admin_Form { * @param bool $check */ public function buildQuickForm($check = FALSE) { - parent::buildQuickForm(); + $this->buildQuickEntityForm(); - if ($this->_action & CRM_Core_Action::DELETE) { + if ($this->isDeleteContext()) { return; } $attributes = CRM_Core_DAO::getAttribute('CRM_Financial_DAO_PaymentProcessor'); - $this->add('text', 'name', ts('Name'), - $attributes['name'], TRUE - ); - $this->addRule('name', ts('Name already exists in Database.'), 'objectExists', [ 'CRM_Financial_DAO_PaymentProcessor', $this->_id, @@ -190,10 +234,7 @@ class CRM_Admin_Form_PaymentProcessor extends CRM_Admin_Form { CRM_Core_Config::domainID(), ]); - $this->add('text', 'description', ts('Description'), - $attributes['description'] - ); - + // @todo - remove this & let the entityForm do it - need to make sure we are handling the js though. $this->add('select', 'payment_processor_type_id', ts('Payment Processor Type'), @@ -383,6 +424,9 @@ class CRM_Admin_Form_PaymentProcessor extends CRM_Admin_Form { /** * Process the form submission. + * + * @throws \CiviCRM_API3_Exception + * @throws \CRM_Core_Exception */ public function postProcess() { @@ -428,6 +472,8 @@ class CRM_Admin_Form_PaymentProcessor extends CRM_Admin_Form { * @param array $values * @param int $domainID * @param bool $test + * + * @throws \CiviCRM_API3_Exception */ public function updatePaymentProcessor(&$values, $domainID, $test) { if ($test) { diff --git a/CRM/Financial/DAO/PaymentProcessor.php b/CRM/Financial/DAO/PaymentProcessor.php index 48676c5991..339daccc5e 100644 --- a/CRM/Financial/DAO/PaymentProcessor.php +++ b/CRM/Financial/DAO/PaymentProcessor.php @@ -6,7 +6,7 @@ * * Generated from xml/schema/CRM/Financial/PaymentProcessor.xml * DO NOT EDIT. Generated by CRM_Core_CodeGen - * (GenCodeChecksum:6d3b0b9b13fae223bc45c6c1e4ce7b94) + * (GenCodeChecksum:0bd325aff061b6eea4854ef63757772a) */ /** @@ -275,6 +275,9 @@ class CRM_Financial_DAO_PaymentProcessor extends CRM_Core_DAO { 'entity' => 'PaymentProcessor', 'bao' => 'CRM_Financial_BAO_PaymentProcessor', 'localizable' => 0, + 'html' => [ + 'type' => 'Text', + ], ], 'payment_processor_type_id' => [ 'name' => 'payment_processor_type_id', diff --git a/templates/CRM/Admin/Form/PaymentProcessor.tpl b/templates/CRM/Admin/Form/PaymentProcessor.tpl index 250500270d..9430a87250 100644 --- a/templates/CRM/Admin/Form/PaymentProcessor.tpl +++ b/templates/CRM/Admin/Form/PaymentProcessor.tpl @@ -30,20 +30,18 @@ {if $action eq 8}
-
- {ts}WARNING: Deleting this Payment Processor may result in some transaction pages being rendered inactive.{/ts} {ts}Do you want to continue?{/ts} +
+ {$deleteMessage|escape}
{else} - - - - - - - - - + {* This works for the fields managed from the EntityFields trait - see RelationshipType.tpl for end goal in this tpl *} + {foreach from=$entityFields item=fieldSpec} + {assign var=fieldName value=$fieldSpec.name} + + {include file="CRM/Core/Form/Field.tpl"} + + {/foreach} diff --git a/xml/schema/Financial/PaymentProcessor.xml b/xml/schema/Financial/PaymentProcessor.xml index 76d1ef13be..ce5e3250ab 100644 --- a/xml/schema/Financial/PaymentProcessor.xml +++ b/xml/schema/Financial/PaymentProcessor.xml @@ -64,6 +64,9 @@ Processor Descriptionvarchar255 + + Text + Payment Processor Description.1.8
{$form.payment_processor_type_id.label}{$form.payment_processor_type_id.html} {help id='proc-type'}
{$form.name.label}{$form.name.html}
{$form.description.label}{$form.description.html}