Skip to content

Commit

Permalink
Consolidate DataSource.tpl for Custom import
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed May 26, 2022
1 parent 7c63299 commit 088dc2c
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 91 deletions.
2 changes: 1 addition & 1 deletion CRM/Core/xml/Menu/Import.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<path>civicrm/import/custom</path>
<path_arguments>id=%%id%%</path_arguments>
<title>Import Multi-value Custom Data</title>
<access_arguments>access CiviCRM</access_arguments>
<access_callback>CRM_Custom_Import_Form_DataSource::isAvailable</access_callback>
<page_type>1</page_type>
<page_callback>CRM_Custom_Import_Controller</page_callback>
<weight>420</weight>
Expand Down
16 changes: 14 additions & 2 deletions CRM/Custom/Import/Form/DataSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
6 changes: 5 additions & 1 deletion CRM/Import/Form/DataSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}";
}
Expand Down
69 changes: 1 addition & 68 deletions templates/CRM/Custom/Import/Form/DataSource.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -7,71 +7,4 @@
| and copyright information, see https://civicrm.org/licensing |
+--------------------------------------------------------------------+
*}

{* Import Wizard - Step 1 (choose data source) *}
<div class="crm-block crm-form-block crm-import-datasource-form-block">

{* 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}
<div class="messages warning no-popup">
{ts}This import screen cannot be used because there are no Multi-value custom data groups.{/ts}
</div>
{/if}
<div class="help">
{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'}
</div>
<div id="upload-file" class="form-item">
<div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="top"}</div>
<table class="form-layout">
<tr class="crm-import-uploadfile-form-block-uploadFile">
<td class="label">{$form.uploadFile.label}</td>
<td>{$form.uploadFile.html}<br />
<span class="description">
{ts}File format must be comma-separated-values (CSV).{/ts}
</span>
</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>{ts 1=$uploadSize}Maximum Upload File Size: %1 MB{/ts}</td>
</tr>
<tr class="crm-import-form-block-skipColumnHeader">
<td>&nbsp;</td>
<td>{$form.skipColumnHeader.html} {$form.skipColumnHeader.label}<br />
<span class="description">
{ts}Check this box if the first row of your file consists of field names (Example: "Contact ID", "Participant Role").{/ts}
</span>
</td>
</tr>
<tr class="crm-import-uploadfile-form-block-multipleCustomData">
<td class="label">{$form.multipleCustomData.label}</td>
<td><span>{$form.multipleCustomData.html}</span> </td>
</tr>
<tr class="crm-import-uploadfile-from-block-contactType">
<td class="label">{$form.contactType.label}</td>
<td>{$form.contactType.html}</td>
</tr>

<tr class="crm-import-datasource-form-block-fieldSeparator">
<td class="label">{$form.fieldSeparator.label} {help id='id-fieldSeparator' file='CRM/Contact/Import/Form/DataSource'}</td>
<td>{$form.fieldSeparator.html}</td>
</tr>
<tr class="crm-import-uploadfile-form-block-date_format">
{include file="CRM/Core/Date.tpl"}
</tr>
{if $savedMapping}
<tr class="crm-import-uploadfile-form-block-savedMapping">
<td class="label">{$form.savedMapping.label}</td>
<td><span>{$form.savedMapping.html}</span> </td>
</tr>
<tr>
<td>&nbsp;</td>
<td class="description">{ts}Select Saved Mapping, or leave blank to create a new mapping.{/ts}</td>
{/if}
</tr>
</table>
<div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="bottom"}</div>
</div>
</div>
{include file="CRM/Import/Form/DataSource.tpl"}
44 changes: 25 additions & 19 deletions templates/CRM/Import/Form/DataSource.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -34,27 +34,33 @@
</span>
</td>
</tr>
{if array_key_exists('contactType', $form)}
<tr class="crm-import-uploadfile-from-block-contactType">
<td class="label">{$form.contactType.label}</td>
<td>{$form.contactType.html}<br />
<span class="description">
{if array_key_exists('contactType', $form)}
<tr class="crm-import-uploadfile-from-block-contactType">
<td class="label">{$form.contactType.label}</td>
<td>{$form.contactType.html}<br />
<span class="description">
{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}
</span>
</td>
</tr>
{/if}
{if array_key_exists('onDuplicate', $form)}
<tr class="crm-import-uploadfile-from-block-onDuplicate">
<td class="label">{$form.onDuplicate.label}</td>
<td>{$form.onDuplicate.html} {help id="id-onDuplicate"}</td>
</tr>
{/if}
<tr class="crm-import-datasource-form-block-fieldSeparator">
<td class="label">{$form.fieldSeparator.label} {help id='id-fieldSeparator' file='CRM/Contact/Import/Form/DataSource'}</td>
<td>{$form.fieldSeparator.html}</td>
</tr>
</td>
</tr>
{/if}
{foreach from=$import_options item=import_option}
<tr class="crm-import-uploadfile-form-block-{$import_option}">
<td class="label">{$form.$import_option.label}</td>
<td><span>{$form.$import_option.html}</span> </td>
</tr>
{/foreach}
{if array_key_exists('onDuplicate', $form)}
<tr class="crm-import-uploadfile-from-block-onDuplicate">
<td class="label">{$form.onDuplicate.label}</td>
<td>{$form.onDuplicate.html} {help id="id-onDuplicate"}</td>
</tr>
{/if}
<tr class="crm-import-datasource-form-block-fieldSeparator">
<td class="label">{$form.fieldSeparator.label} {help id='id-fieldSeparator' file='CRM/Contact/Import/Form/DataSource'}</td>
<td>{$form.fieldSeparator.html}</td>
</tr>
<tr class="crm-import-uploadfile-form-block-date">{include file="CRM/Core/Date.tpl"}</tr>
{if $savedMapping}
<tr class="crm-import-uploadfile-form-block-savedMapping">
Expand Down

0 comments on commit 088dc2c

Please sign in to comment.