* 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;
*/
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.
*
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();
* @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,
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'),
/**
* Process the form submission.
+ *
+ * @throws \CiviCRM_API3_Exception
+ * @throws \CRM_Core_Exception
*/
public function postProcess() {
* @param array $values
* @param int $domainID
* @param bool $test
+ *
+ * @throws \CiviCRM_API3_Exception
*/
public function updatePaymentProcessor(&$values, $domainID, $test) {
if ($test) {
{if $action eq 8}
<div class="messages status no-popup">
- <div class="icon inform-icon"></div>
- {ts}WARNING: Deleting this Payment Processor may result in some transaction pages being rendered inactive.{/ts} {ts}Do you want to continue?{/ts}
+ <div class="icon inform-icon"></div>
+ {$deleteMessage|escape}
</div>
{else}
<table class="form-layout-compressed">
- <tr class="crm-paymentProcessor-form-block-payment_processor_type">
- <td class="label">{$form.payment_processor_type_id.label}</td><td>{$form.payment_processor_type_id.html} {help id='proc-type'}</td>
- </tr>
- <tr class="crm-paymentProcessor-form-block-name">
- <td class="label">{$form.name.label}</td><td>{$form.name.html}</td>
- </tr>
- <tr class="crm-paymentProcessor-form-block-description">
- <td class="label">{$form.description.label}</td><td>{$form.description.html}</td>
- </tr>
+ {* 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}
+ <tr class="crm-{$entityInClassFormat}-form-block-{$fieldName}">
+ {include file="CRM/Core/Form/Field.tpl"}
+ </tr>
+ {/foreach}
<tr class="crm-paymentProcessor-form-block-financial_account">
<td class="label">{$form.financial_account_id.label}</td>