PHP code example of boboldehampsink / import

1. Go to this page and download the library: Download boboldehampsink/import 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/ */

    

boboldehampsink / import example snippets


/**
 * Modify data just before importing
 *
 * @param BaseElementModel $element  The current element receiving import data.
 * @param array            $map      Mapping of data between CSV -> Craft fields.
 * @param array            $data     Raw data provided for this row.
 */
public function modifyImportRow($element, $map, $data)
{
    // Map data to fields
    $fields = array_combine($map, $data);

    // Initialize content array
    $content = array();

    // Arrange your content in a way that makes sense for your plugin
    foreach ($fields as $handle => $value) {
        $content[$handle] = $value;
    }

    // Set modified content
    $element->setContentFromPost($content);
}

/**
 * For custom field types, replace default <option> with custom HTML
 *
 * @return array  Mapping between custom field type -> custom <option> template
 */
public function registerImportOptionPaths()
{
    return array(
        'MyPlugin_MyFieldType' => 'myplugin/customImportOption.html',
    );
}