* @copyright CiviCRM LLC https://civicrm.org/licensing
*/
+use Civi\Api4\CustomGroup;
+
/**
* This class gets the name of the file to upload
*/
return 'custom_field_import';
}
+ /**
+ * Multiple field custom groups.
+ *
+ * @var array
+ */
+ protected $customFieldGroups;
+
+ /**
+ * Get multi-field custom groups.
+ *
+ * @return array
+ * @throws \CRM_Core_Exception
+ */
+ protected function getCustomGroups(): array {
+ if (isset($this->customFieldGroups)) {
+ return $this->customFieldGroups;
+ }
+ $this->customFieldGroups = [];
+ // If we make the permission TRUE is it too restrictive?
+ $fields = CustomGroup::get(FALSE)->addSelect('id', 'title')
+ ->addWhere('is_multiple', '=', TRUE)
+ ->addWhere('is_active', '=', TRUE)->execute();
+ foreach ($fields as $field) {
+ $this->customFieldGroups[$field['id']] = $field['title'];
+ }
+ return $this->customFieldGroups;
+ }
+
+ /**
+ * Get an error message to assign to the template.
+ *
+ * @return string
+ */
+ protected function getErrorMessage(): string {
+ return empty($this->getCustomGroups()) ? ts('This import screen cannot be used because there are no Multi-value custom data groups.') : '';
+ }
+
/**
* Get the import entity (translated).
*
/**
* @return array
+ * @throws \CRM_Core_Exception
*/
- public function setDefaultValues() {
+ public function setDefaultValues(): array {
$config = CRM_Core_Config::singleton();
$defaults = [
'contactType' => CRM_Import_Parser::CONTACT_INDIVIDUAL,
'fieldSeparator' => $config->fieldSeparator,
- 'multipleCustomData' => $this->_id,
+ // Perhaps never used, but permits url passing of the group.
+ 'multipleCustomData' => CRM_Utils_Request::retrieve('id', 'Positive', $this),
];
$loadedMapping = $this->get('loadedMapping');
/**
* Build the form object.
*
- * @return void
+ * @throws \CRM_Core_Exception
*/
- public function buildQuickForm() {
+ public function buildQuickForm(): void {
parent::buildQuickForm();
- // Perhaps never used, but permits url passing of the group.
- $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE);
- $multipleCustomData = CRM_Core_BAO_CustomGroup::getMultipleFieldGroup();
- $this->assign('fieldGroups', $multipleCustomData);
- $this->add('select', 'multipleCustomData', ts('Multi-value Custom Data'), ['' => ts('- select -')] + $multipleCustomData, TRUE);
-
+ $this->add('select', 'multipleCustomData', ts('Multi-value Custom Data'), ['' => ts('- select -')] + $this->getCustomGroups(), TRUE);
$this->addContactTypeSelector();
}
+--------------------------------------------------------------------+
*}
+{* Import Wizard - Step 1 (choose data source) *}
{* 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}
+ {if $errorMessage}
+ <div class="messages warning no-popup">
+ {$errorMessage}
+ </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">
+ <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> </td>
- <td>{ts 1=$uploadSize}Maximum Upload File Size: %1 MB{/ts}</td>
- </tr>
- <tr class="crm-import-form-block-skipColumnHeader">
- <td> </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>
+ </td>
+ </tr>
+ <tr>
+ <td> </td>
+ <td>{ts 1=$uploadSize}Maximum Upload File Size: %1 MB{/ts}</td>
+ </tr>
+ <tr class="crm-import-form-block-skipColumnHeader">
+ <td> </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> </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>
+ <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> </td>
+ <td class="description">{ts}Select Saved Mapping, or leave blank to create a new mapping.{/ts}</td>
+ </tr>
+ {/if}
+ </table>
+ <div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="bottom"}</div>
</div>
- </div>
+</div>