import
import copied to clipboard
Importing users runs modify hook, but ignores it
I'm trying to import some users and I have this modify in my business logic plugin:
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;
}
$name = explode(' ', $data[2], 2);
$content['firstName'] = $name[0];
$content['lastName'] = $name[1];
// Set modified content
$element->setContentFromPost($content);
}
The users are importing successfully, and the hook is running (I can ::log
from it) but none of the modifications take effect. I'm not getting any errors (checked log files & craft_import_log table).
Check out this answer:
http://craftcms.stackexchange.com/a/16265/153
You'll have to make some adjustments. ie. check for a particular field handle (name?) and get your manipulations inside the foreach loop. Are you importing into a table by chance?
If you are setting the default firstName
and lastName
fields on a UserModel, you can't do that using setContentFromPost()
.
Instead, try setting them directly on the $element
like this:
$element->firstName = $name[0];
$element->lastName = $name[1];