function feeds_tamper_conditional_form in Feeds Tamper Conditional 7
Form for plugin.
1 string reference to 'feeds_tamper_conditional_form'
File
- plugins/
feeds_tamper_conditional.inc, line 19
Code
function feeds_tamper_conditional_form($importer, $element_key, $settings) {
$form = array();
$form['help'] = array(
'#markup' => t('Only writes the field if a condition is met. Condition can be based on the value
of any field.'),
);
// @todo add a hook here to allow modules to add their own format for the options in the dropdown.
$feeds_filemaker = get_class($importer->parser) == 'FeedsFileMakerParser' ? TRUE : FALSE;
// Grab all of the mapping sources, for addition to the conditional field select.
$replace = array();
$mappings = $importer->processor->config['mappings'];
foreach ($mappings as $mapping) {
if ($feeds_filemaker) {
$prefix = $importer->config['parser']['config']['mappings'][$mapping['source']]['mapping'] . ' - ';
}
else {
$prefix = '';
}
$replace[$mapping['source']] = $prefix . $mapping['target'] . ' [' . $mapping['source'] . ']';
}
// The field mapping to check. The user chooses which field should be tested
// against the condition.
$form['conditional_field'] = array(
'#type' => 'select',
'#title' => t('Field mapping to check'),
'#options' => $replace,
'#required' => TRUE,
'#default_value' => isset($settings['conditional_field']) ? $settings['conditional_field'] : '',
);
// The operators that can be used to check whether the condition has been met
$operators = array(
'equals' => 'Equals',
'not_equals' => 'Does not equal',
'begins' => 'Begins with',
'ends' => 'Ends with',
'greater' => 'Greater than',
'greater_equal' => 'Greater than or equal',
'less' => 'Less than',
'less_equal' => 'Less than or equal',
'contains' => 'Contains',
'not_contains' => 'Does not contain',
'empty' => 'Is empty',
'set' => 'Is set',
'null' => 'Is null',
'array' => 'Is array',
'bool' => 'Is boolean',
'int' => 'Is integer',
'float' => 'Is float',
'numeric' => 'Is numeric',
'string' => 'Is string',
);
// The operator to use for validating the condition.
$form['operator'] = array(
'#type' => 'select',
'#title' => t('Operator'),
'#options' => $operators,
'#default_value' => isset($settings['operator']) ? $settings['operator'] : '',
'#required' => TRUE,
);
// Option to Negate is applicable to conditions such as isset(), empty() etc.
$form['negate'] = array(
'#type' => 'checkbox',
'#title' => t('Negate'),
'#default_value' => isset($settings['negate']) ? $settings['negate'] : 0,
'#states' => array(
'visible' => array(
// action to take.
'select[name="settings[operator]"]' => array(
array(
'value' => 'begins',
),
array(
'value' => 'ends',
),
array(
'value' => 'empty',
),
array(
'value' => 'set',
),
array(
'value' => 'null',
),
array(
'value' => 'array',
),
array(
'value' => 'bool',
),
array(
'value' => 'int',
),
array(
'value' => 'float',
),
array(
'value' => 'numeric',
),
array(
'value' => 'string',
),
),
),
),
);
// The value to check for
$form['value'] = array(
'#title' => t('Value to check'),
'#default_value' => isset($settings['value']) ? $settings['value'] : '',
'#type' => 'textfield',
'#required' => FALSE,
'#states' => array(
'invisible' => array(
// action to take.
'select[name="settings[operator]"]' => array(
array(
'value' => 'empty',
),
array(
'value' => 'set',
),
array(
'value' => 'null',
),
array(
'value' => 'array',
),
array(
'value' => 'bool',
),
array(
'value' => 'int',
),
array(
'value' => 'float',
),
array(
'value' => 'numeric',
),
array(
'value' => 'string',
),
),
),
),
);
return $form;
}