From 1544a79cc85e281d271c19e47be04e19de556dbe Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Sat, 14 May 2022 09:10:53 +1200 Subject: [PATCH] Consolidate DataSource.tpl for Custom import --- CRM/Core/xml/Menu/Import.xml | 2 +- CRM/Custom/Import/Form/DataSource.php | 16 ++++- CRM/Import/Form/DataSource.php | 6 +- .../CRM/Custom/Import/Form/DataSource.tpl | 69 +------------------ templates/CRM/Import/Form/DataSource.tpl | 44 +++++++----- 5 files changed, 46 insertions(+), 91 deletions(-) diff --git a/CRM/Core/xml/Menu/Import.xml b/CRM/Core/xml/Menu/Import.xml index 33d935c63421..affd37169b48 100644 --- a/CRM/Core/xml/Menu/Import.xml +++ b/CRM/Core/xml/Menu/Import.xml @@ -35,7 +35,7 @@ civicrm/import/custom id=%%id%% Import Multi-value Custom Data - access CiviCRM + CRM_Custom_Import_Form_DataSource::isAvailable 1 CRM_Custom_Import_Controller 420 diff --git a/CRM/Custom/Import/Form/DataSource.php b/CRM/Custom/Import/Form/DataSource.php index 71b2eb52b96d..3b6f9762a666 100644 --- a/CRM/Custom/Import/Form/DataSource.php +++ b/CRM/Custom/Import/Form/DataSource.php @@ -74,12 +74,24 @@ public function buildQuickForm() { parent::buildQuickForm(); $multipleCustomData = CRM_Core_BAO_CustomGroup::getMultipleFieldGroup(); - $this->assign('fieldGroups', $multipleCustomData); + if (!$multipleCustomData) { + CRM_Core_Error::statusBounce(ts('This import screen cannot be used because there are no Multi-value custom data groups')); + } $this->add('select', 'multipleCustomData', ts('Multi-value Custom Data'), ['' => ts('- select -')] + $multipleCustomData, TRUE); - + // Assign an array of fields that are specific to this import to be included. + $this->assign('import_options', ['multipleCustomData']); $this->addContactTypeSelector(); } + /** + * Is the custom data import available for use. + * + * @return bool + */ + public static function isAvailable(): bool { + return CRM_Core_Permission::check('access CiviCRM') && CRM_Core_BAO_CustomGroup::getMultipleFieldGroup(); + } + /** * Process the uploaded file. * diff --git a/CRM/Import/Form/DataSource.php b/CRM/Import/Form/DataSource.php index 19fea5947c19..1045acb08725 100644 --- a/CRM/Import/Form/DataSource.php +++ b/CRM/Import/Form/DataSource.php @@ -23,8 +23,12 @@ abstract class CRM_Import_Form_DataSource extends CRM_Import_Forms { * Set variables up before form is built. */ public function preProcess() { + // Import options as an array of field names specific to the import + // (used by custom field import at time or writing) that will be included + // in the tpl. + $this->assign('import_options', []); $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE); - $params = "reset=1"; + $params = 'reset=1'; if ($this->_id) { $params .= "&id={$this->_id}"; } diff --git a/templates/CRM/Custom/Import/Form/DataSource.tpl b/templates/CRM/Custom/Import/Form/DataSource.tpl index a5fde9dd84b6..5395b37fcf7f 100644 --- a/templates/CRM/Custom/Import/Form/DataSource.tpl +++ b/templates/CRM/Custom/Import/Form/DataSource.tpl @@ -7,71 +7,4 @@ | and copyright information, see https://civicrm.org/licensing | +--------------------------------------------------------------------+ *} - -{* Import Wizard - Step 1 (choose data source) *} -
- - {* WizardHeader.tpl provides visual display of steps thru the wizard as well as title for current step *} - {include file="CRM/common/WizardHeader.tpl"} - {if !$fieldGroups} -
- {ts}This import screen cannot be used because there are no Multi-value custom data groups.{/ts} -
- {/if} -
- {ts 1=$importEntity 2= $importEntities}The %1 Import Wizard allows you to easily upload %2 from other applications into CiviCRM.{/ts} - {ts}Files to be imported must be in the 'comma-separated-values' format (CSV) and must contain data needed to match an existing contact in your CiviCRM database.{/ts} {help id='upload'} -
-
-
{include file="CRM/common/formButtons.tpl" location="top"}
- - - - - - - - - - - - - - - - - - - - - - - - - - - - {include file="CRM/Core/Date.tpl"} - - {if $savedMapping} - - - - - - - - {/if} - -
{$form.uploadFile.label}{$form.uploadFile.html}
- - {ts}File format must be comma-separated-values (CSV).{/ts} - -
 {ts 1=$uploadSize}Maximum Upload File Size: %1 MB{/ts}
 {$form.skipColumnHeader.html} {$form.skipColumnHeader.label}
- - {ts}Check this box if the first row of your file consists of field names (Example: "Contact ID", "Participant Role").{/ts} - -
{$form.multipleCustomData.label}{$form.multipleCustomData.html}
{$form.contactType.label}{$form.contactType.html}
{$form.fieldSeparator.label} {help id='id-fieldSeparator' file='CRM/Contact/Import/Form/DataSource'}{$form.fieldSeparator.html}
{$form.savedMapping.label}{$form.savedMapping.html}
 {ts}Select Saved Mapping, or leave blank to create a new mapping.{/ts}
-
{include file="CRM/common/formButtons.tpl" location="bottom"}
-
-
+{include file="CRM/Import/Form/DataSource.tpl"} diff --git a/templates/CRM/Import/Form/DataSource.tpl b/templates/CRM/Import/Form/DataSource.tpl index b1b0308c7c06..b57fddb3d93d 100644 --- a/templates/CRM/Import/Form/DataSource.tpl +++ b/templates/CRM/Import/Form/DataSource.tpl @@ -34,27 +34,33 @@ - {if array_key_exists('contactType', $form)} - - {$form.contactType.label} - {$form.contactType.html}
- + {if array_key_exists('contactType', $form)} + + {$form.contactType.label} + {$form.contactType.html}
+ {ts 1=$importEntities}Select 'Individual' if you are importing %1 made by individual persons.{/ts} - {ts 1=$importEntities}Select 'Organization' or 'Household' if you are importing %1 made by contacts of that type. (NOTE: Some built-in contact types may not be enabled for your site.){/ts} + {ts 1=$importEntities}Select 'Organization' or 'Household' if you are importing %1 made by contacts of that type. (NOTE: Some built-in contact types may not be enabled for your site.){/ts} - - - {/if} - {if array_key_exists('onDuplicate', $form)} - - {$form.onDuplicate.label} - {$form.onDuplicate.html} {help id="id-onDuplicate"} - - {/if} - - {$form.fieldSeparator.label} {help id='id-fieldSeparator' file='CRM/Contact/Import/Form/DataSource'} - {$form.fieldSeparator.html} - + + + {/if} + {foreach from=$import_options item=import_option} + + {$form.$import_option.label} + {$form.$import_option.html} + + {/foreach} + {if array_key_exists('onDuplicate', $form)} + + {$form.onDuplicate.label} + {$form.onDuplicate.html} {help id="id-onDuplicate"} + + {/if} + + {$form.fieldSeparator.label} {help id='id-fieldSeparator' file='CRM/Contact/Import/Form/DataSource'} + {$form.fieldSeparator.html} + {include file="CRM/Core/Date.tpl"} {if $savedMapping}