View source
<?php
$plugin = array(
'form' => 'farm_import_boolean_default_form',
'callback' => 'farm_import_boolean_default_callback',
'name' => 'Convert to boolean (with default)',
'multi' => 'direct',
'category' => 'Text',
);
function farm_import_boolean_default_form($importer, $element_key, $settings) {
$form = array();
$form['default_value'] = array(
'#type' => 'radios',
'#title' => t('Default value'),
'#options' => array(
0 => 'False',
1 => 'True',
),
'#default_value' => !empty($settings['default_value']) ? 1 : 0,
);
return $form;
}
function farm_import_boolean_default_callback($result, $item_key, $element_key, &$field, $settings, $source) {
$value = $field;
$default_value = isset($settings['default_value']) ? $settings['default_value'] : TRUE;
$value = drupal_strtolower($value);
$allowed_values = array(
0 => array(
'false',
'f',
'no',
'n',
'0',
),
1 => array(
'true',
't',
'yes',
'y',
'1',
),
);
foreach ($allowed_values as $boolean => $options) {
foreach ($options as $option) {
if ($value == $option) {
$field = $boolean;
return;
}
}
}
$field = $default_value;
}