function customfilter_rule_edit in Custom filter 6
Same name and namespace in other branches
- 7.2 customfilter.module \customfilter_rule_edit()
- 7 customfilter.module \customfilter_rule_edit()
Return the replacement rule edit form.
1 string reference to 'customfilter_rule_edit'
- customfilter_menu in ./
customfilter.module - Implements hook_menu().
File
- ./
customfilter.admin.inc, line 434 - Administration page callbacks for Custom filter.
Code
function customfilter_rule_edit($form_state, $op, $fid, $rid = 0) {
$filters = _customfilter_get_filters();
$form = array();
if ($op == 'edit') {
$item = db_fetch_array(db_query("SELECT * FROM {customfilter_rule} WHERE rid = %d", $rid));
}
elseif ($op == 'add') {
$item = array(
'rid' => (int) db_result(db_query("SELECT MAX(rid) FROM {customfilter_rule}")) + 1,
'prid' => $rid,
'fid' => $fid,
'name' => '$1',
'description' => '',
'enabled' => 1,
'matches' => 1,
'pattern' => '/regex/i',
'replacement' => 'Regular Expressions',
'code' => 0,
'weight' => 0,
);
}
$matchopt = drupal_map_assoc(range(0, 99));
$form['rid'] = array(
'#type' => 'value',
'#value' => $item['rid'],
);
$form['fid'] = array(
'#type' => 'value',
'#value' => $fid,
);
$form['prid'] = array(
'#type' => 'value',
'#value' => $item['prid'],
);
$form['operation'] = array(
'#type' => 'value',
'#value' => $op,
);
if ($item['prid'] != 0) {
$form['matches'] = array(
'#type' => 'select',
'#title' => t('# Match'),
'#description' => t('n-th matched substring in parent rule. This replacement rule will replace only for that substring.'),
'#options' => $matchopt,
'#default_value' => $item['matches'],
);
}
$form['name'] = array(
'#type' => 'textfield',
'#description' => t('The name of this replacement rule.'),
'#title' => t('Name'),
'#default_value' => $item['name'],
'#required' => TRUE,
);
$form['weight'] = array(
'#title' => t('Weight'),
'#default_value' => $item['weight'],
);
$form['enabled'] = array(
'#type' => 'checkbox',
'#title' => t('Enabled'),
'#description' => t('If selected, the rule is used.'),
'#default_value' => $item['enabled'],
);
$form['description'] = array(
'#type' => 'textarea',
'#title' => t('Description'),
'#description' => t('The description of this rule.'),
'#default_value' => $item['description'],
);
$form['pattern'] = array(
'#type' => 'textarea',
'#title' => t('Pattern'),
'#description' => t('The regular expression to use. Look at <a href="http://www.php.net/manual/en/regexp.reference.php">Regular Expression Details</a> for more help.'),
'#default_value' => $item['pattern'],
'#rows' => 3,
);
$form['code'] = array(
'#type' => 'checkbox',
'#title' => t('PHP Code'),
'#description' => t('If selected, the replacement text is PHP code.'),
'#default_value' => $item['code'],
);
$form['replacement']['replacement'] = array(
'#type' => 'textarea',
'#title' => t('Replacement text'),
'#description' => t('The replacement text that will replace the matched string. Use $n (i.e. $1, $25) or ${n} (i.e. ${1}, ${25}), with n range from 0 to 99, to get the n-th original strings matched ($0 represents the entire matched string). If you select <strong>PHP Code</strong>, you can enter PHP code that will be executed during the elaboration of the rules. n-th matched string is provided in <code>$matches[n]</code>, and there is a global variable <code>$vars</code> you can use to store values that will be kept during the execution of different rules of the same filter. PHP code must set a value for <code>$result</code>, and must not be entered between <code><</code><code>?php ?></code>. Note that executing incorrect PHP-code can break your Drupal site.'),
'#default_value' => $item['replacement'],
'#rows' => 16,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
);
return $form;
}