1. Go to this page and download the library: Download teppokoivula/import-tool library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
teppokoivula / import-tool example snippets
$config->ImportTools = [
'profiles' => [
'members' => [
'label' => 'Members',
'template' => 'member',
'parent' => 1282,
'values' => [
// note: key (here 'title') should be a reference to a column name/header from the import file
'title' => [
'field' => 'title',
'sanitize' => 'text',
],
'first_name' => [
'field' => 'first_name',
'sanitize' => 'text',
],
'last_name' => [
'field' => 'last_name',
'sanitize' => 'text',
],
'date_of_birth' => [
'field' => 'date_of_birth',
'sanitize' => 'date',
],
'email' => [
'field' => 'email',
'sanitize' => 'email',
],
// if you want to set page values dynamically with code, you can use a key name that doesn't match any
// column name/header from the import file:
'import_timestamp' => [
'callback' => function($page, $field_name, $value, $args) {
$page->import_timestamp = date('Y-m-d H:i:s');
},
],
],
'limit' => 10,
'on_duplicate' => 'make_unique',
'on_missing_page_ref' => 'create',
'reader_settings' => [
'delimiter' => ',',
'enclosure' => '"',
],
],
],
// set to true if users should be able to provide custom profile configuration settings runtime;
// please note, though, that this is an advanced option that should only be used when necessary!
'allow_overriding_profile_configuration' => false,
];
'title' => [
'sanitize' => 'text',
],
'start_date' => [
'field' => 'start_date',
'sanitize' => function($value, $args) {
if (!empty($value) && is_string($value)) {
// remove extraneous day abbreviation (e.g. "mon 1.1.2023") from date
$value = preg_replace('/^[a-z]+ */i', '', $value);
}
return wire()->sanitizer->date($value);
}
],
[
'callback' => function($page, $field, $value, $args) {
// time provided as a separate column, but we want to combine it with date
$page->start_date = implode(' ', array_filter([
date('j.n.Y', $page->getUnformatted('start_date')),
$value,
]));
}
],