Skip to content

Instantly share code, notes, and snippets.

@boboldehampsink
Created June 8, 2014 10:43
Show Gist options
  • Save boboldehampsink/47aaa01674284721998b to your computer and use it in GitHub Desktop.
Save boboldehampsink/47aaa01674284721998b to your computer and use it in GitHub Desktop.
registerImportOperation example
// Register special hook for Markdown processing
function registerImportOperation(&$data, $handle) {
// Get field info
$field = craft()->fields->getFieldByHandle($handle);
// If it's a field ofcourse
if(!is_null($field)) {
// For some fieldtypes the're special rules
switch($field->type) {
case ImportModel::FieldTypeRichText:
// Replace br's with newlines
$data = str_replace(' <br> ', '<br>', $data);
$data = str_replace('<br>', "\r\n", $data);
// Fix links
$data = str_replace('] (http://', '](http://', $data);
// Parse markdown
$data = StringHelper::parseMarkdown($data);
break;
}
}
return $data;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment