From 84da9b33590e5250ae25e2c279f957512235a1c3 Mon Sep 17 00:00:00 2001 From: Chuck Scott Date: Wed, 13 Dec 2017 08:54:21 -0500 Subject: [PATCH] Additional documentation and minor problem fixes. --- classes/data/dataCustomFields.php | 7 +++++-- config/plugin.ini | 10 ++++++++++ models/admin/ajax/customFields.php | 5 +++++ models/admin/customFields/index.php | 11 ++++++++--- setup/commonHooks.php | 13 +++++++------ views/admin/ajax/newField.html | 6 +++--- views/admin/customFields/index.html | 12 ++++-------- 7 files changed, 42 insertions(+), 22 deletions(-) diff --git a/classes/data/dataCustomFields.php b/classes/data/dataCustomFields.php index af8c507..f106a69 100644 --- a/classes/data/dataCustomFields.php +++ b/classes/data/dataCustomFields.php @@ -149,8 +149,7 @@ class GlmDataFieldsCustomFields extends GlmDataAbstract // Field Type 'field_type' => array( 'field' => 'field_type', - 'type' => 'list', - 'list' => $this->config['custom_field_types'], + 'type' => 'text', 'required' => true, 'use' => 'a' ), @@ -190,6 +189,10 @@ class GlmDataFieldsCustomFields extends GlmDataAbstract */ public function entryPostProcessing($r, $a) { + + // Get field type description from ini file. + $r['field_type_descr'] = $this->config['custom_field_type'][$r['field_type']]; + return $r; } diff --git a/config/plugin.ini b/config/plugin.ini index 77b9ef0..faf7203 100644 --- a/config/plugin.ini +++ b/config/plugin.ini @@ -4,3 +4,13 @@ ; ; Place any static configuration parameters here. ; + + +; +; Custom Field Types +; +custom_field_type['text'] = 'Single Line Text Field' +custom_field_type['textarea'] = 'Multi-Line Text Area' +custom_field_type['checkbox'] = 'Checkbox' +; custom_field_type['integer'] = 'Integer Number' +; custom_field_type['float'] = 'Floating Point number' diff --git a/models/admin/ajax/customFields.php b/models/admin/ajax/customFields.php index e5279b0..3ed14b3 100644 --- a/models/admin/ajax/customFields.php +++ b/models/admin/ajax/customFields.php @@ -102,6 +102,11 @@ class GlmMembersAdmin_ajax_customFields extends GlmDataFieldsCustomFields if (!is_array($customField) || !$customField['status']) { echo "0"; } else { + + // Add description for the selected field type + $customField['fieldData']['field_type_descr'] = $this->config['custom_field_type'][$customField['fieldData']['field_type']]; + + // Produce HTML for the new field $viewFile = 'admin/ajax/newField.html'; $newFieldHtml = $this->generateHTML($customField, $viewFile); echo $newFieldHtml; diff --git a/models/admin/customFields/index.php b/models/admin/customFields/index.php index 926abbd..3985ba0 100644 --- a/models/admin/customFields/index.php +++ b/models/admin/customFields/index.php @@ -181,10 +181,15 @@ class GlmMembersAdmin_customFields_index extends GlmDataFieldsCustomFields } - $where .= " AND fid = '$fid' "; + // Build custom field types array for building picklist + $fieldTypes = array(); + foreach ($this->config['custom_field_type'] as $typeKey=>$typeVal) { + $fieldTypes[$typeKey] = array('type_name' => $typeKey, 'prompt' => $typeVal); + } // Get list of Custom Fields - $custom_fields = $this->getList( $where ); + $where .= " AND fid = '$fid' "; + $custom_fields = $this->getList( $where, false, true); if ( isset($custom_fields) && $custom_fields && count( $custom_fields ) > 0 ) { $haveCustomFields = true; @@ -196,7 +201,7 @@ class GlmMembersAdmin_customFields_index extends GlmDataFieldsCustomFields 'settingsUpdated' => $settings_updated, 'settingsUpdateError' => $settings_update_error, 'custom_fields' => $custom_fields, - 'field_types' => $this->config['custom_field_types'], + 'fieldTypes' => $fieldTypes, 'haveCustomFields' => $haveCustomFields, 'fid' => $fid, 'glm_action' => $glm_action diff --git a/setup/commonHooks.php b/setup/commonHooks.php index 518c422..72ce77a 100644 --- a/setup/commonHooks.php +++ b/setup/commonHooks.php @@ -65,12 +65,13 @@ add_filter( 'glm-members-customfields-have-fields', function( $haveFields, $fid) /** * Return HTML for a custom fields form segment * - * @param $content string Any supplied content. Form will be appended to this - * @param $fid string Unique ID of form - * @param $recordId integer Optional ID for instance of this form (generally the ID of the associated record) - * If this is 0 then it's assumed this is a new form with no existing data. - * @param $submitId string Optional ID of the submit button for the form this will be part of. - * @param $formData array Optional array of data used to populate form (Not sure we're going to keep this) + * @param $content string Any supplied content. Form will be appended to this + * @param $fid string Unique ID of form + * @param $recordId integer Optional ID for instance of this form (generally the ID of the associated record) + * If this is 0 then it's assumed this is a new form with no existing data. + * @param $parentFormId string Optional ID of the submit button for the form that will have these custom fields added. + * This is used to block submit (if possible) for that form while there's still required custom fields. + * @param $formData array Optional array of data used to populate form (Not sure we're going to keep this) * * returns an array with status and HTML for editing the form. */ diff --git a/views/admin/ajax/newField.html b/views/admin/ajax/newField.html index 39429fd..872931d 100644 --- a/views/admin/ajax/newField.html +++ b/views/admin/ajax/newField.html @@ -1,7 +1,7 @@ {* A single line for the custom fields edit table *} - + {$fieldData.field_name} - {$fieldData.field_type.name} + {$fieldData.field_type_descr} {$fieldData.required.name} + {foreach $fieldTypes as $type} + + {/foreach} @@ -95,7 +91,7 @@ {$t.field_name} - {$t.field_type.name} + {$t.field_type_descr} {$t.required.name} -- 2.17.1