$this->addElement('checkbox', 'doGeocodeAddress', ts('Geocode addresses during import?'));
}
- $this->addElement('text', 'fieldSeparator', ts('Import Field Separator'), ['size' => 2]);
-
if (Civi::settings()->get('address_standardization_provider') === 'USPS') {
$this->addElement('checkbox', 'disableUSPS', ts('Disable USPS address validation during import?'));
}
* It should add all fields necessary to get the data
* uploaded to the temporary table in the DB.
*
- * @param CRM_Core_Form $form
+ * @param CRM_Contact_Import_Form_DataSource|\CRM_Import_Form_DataSourceConfig $form
*
* @throws \CRM_Core_Exception
*/
$uploadSize = round(($uploadFileSize / (1024 * 1024)), 2);
$form->assign('uploadSize', $uploadSize);
$form->add('File', 'uploadFile', ts('Import Data File'), NULL, TRUE);
+ $form->addElement('text', 'fieldSeparator', ts('Import Field Separator'), ['size' => 2]);
$form->setMaxFileSize($uploadFileSize);
$form->addRule('uploadFile', ts('File size should be less than %1 MBytes (%2 bytes)', [
1 => $uploadSize,
]), 'maxfilesize', $uploadFileSize);
$form->addRule('uploadFile', ts('Input file must be in CSV format'), 'utf8File');
$form->addRule('uploadFile', ts('A valid file must be uploaded.'), 'uploadedfile');
-
+ $form->setDataSourceDefaults($this->getDefaultValues());
$form->addElement('checkbox', 'skipColumnHeader', ts('First row contains column headers'));
}
return preg_replace("/^(\u{a0})+|(\u{a0})+$/", '', $string);
}
+ /**
+ * Get default values for csv dataSource fields.
+ *
+ * @return array
+ */
+ public function getDefaultValues(): array {
+ return [
+ 'fieldSeparator' => CRM_Core_Config::singleton()->fieldSeparator,
+ 'skipColumnHeader' => 1,
+ ];
+
+ }
+
}
}
public function setDefaultValues() {
- return [
+ return array_merge($this->dataSourceDefaults, [
'dataSource' => $this->getDefaultDataSource(),
'onDuplicate' => CRM_Import_Parser::DUPLICATE_SKIP,
- 'fieldSeparator' => CRM_Core_Config::singleton()->fieldSeparator,
- ];
+ ]);
}
$this->getDataSourceObject()->initialize();
}
+ /**
+ * Default values for datasource fields.
+ *
+ * @var array
+ */
+ protected $dataSourceDefaults = [];
+
+ /**
+ * Set dataSource default values.
+ *
+ * @param array $dataSourceDefaults
+ *
+ * @return self
+ */
+ public function setDataSourceDefaults(array $dataSourceDefaults): self {
+ $this->dataSourceDefaults = $dataSourceDefaults;
+ return $this;
+ }
+
}
*/
class CRM_Import_Form_DataSourceConfig extends CRM_Import_Forms {
+ /**
+ * Default values for datasource fields.
+ *
+ * @var array
+ */
+ protected $dataSourceDefaults = [];
+
+ /**
+ * Set dataSource default values.
+ *
+ * @param array $dataSourceDefaults
+ *
+ * @return CRM_Import_Form_DataSourceConfig
+ */
+ public function setDataSourceDefaults(array $dataSourceDefaults): CRM_Import_Form_DataSourceConfig {
+ $this->dataSourceDefaults = $dataSourceDefaults;
+ return $this;
+ }
+
/**
* Set variables up before form is built.
*
$defaults[$fieldName] = $this->getSubmittedValue($fieldName);
}
}
+ else {
+ $defaults = array_merge($this->dataSourceDefaults, $defaults);
+ }
return $defaults;
}
<div class="description">{ts}Check this box if the first row of your file consists of field names (Example: 'First Name','Last Name','Email'){/ts}</div>
</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>
</table>
<td><span>{$form.multipleCustomData.html}</span> </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 array_key_exists('savedMapping', $form)}
<tr class="crm-import-uploadfile-form-block-savedMapping">