You are here

function customfilter_filter_edit in Custom filter 5

Same name and namespace in other branches
  1. 6 customfilter.admin.inc \customfilter_filter_edit()
  2. 7.2 customfilter.module \customfilter_filter_edit()
  3. 7 customfilter.module \customfilter_filter_edit()

Edit a filter.

1 string reference to 'customfilter_filter_edit'
customfilter_menu in ./customfilter.module
Implements hook_menu().

File

./customfilter.module, line 607

Code

function customfilter_filter_edit($op, $sid, $fid = 0) {
  if ($op == 'edit') {
    $item = customfilter_get_filter($fid, '*');
  }
  elseif ($op == 'add') {
    $item = array(
      'fid' => 0,
      'parentid' => $fid,
      'sid' => $sid,
      'name' => '$1',
      'description' => '',
      'matches' => 1,
      'pattern' => '/regex/i',
      'replacement' => 'Regular Expressions',
      'func' => 0,
      'weight' => 0,
    );
  }
  $matchopt = array();
  for ($i = 0; $i <= 99; $i++) {
    $matchopt[$i] = $i;
  }
  $form['fid'] = array(
    '#type' => 'value',
    '#value' => $item['fid'],
  );
  $form['sid'] = array(
    '#type' => 'value',
    '#value' => $sid,
  );
  $form['parentid'] = array(
    '#type' => 'value',
    '#value' => $item['parentid'],
  );
  $form['operation'] = array(
    '#type' => 'value',
    '#value' => $op,
  );
  if ($item['parentid'] != 0) {
    $form['matches'] = array(
      '#type' => 'select',
      '#title' => t('# Match'),
      '#options' => $matchopt,
      '#default_value' => $item['matches'],
      '#description' => t('Matches.'),
    );
  }
  $form['name'] = array(
    '#type' => 'textfield',
    '#title' => t('Name'),
    '#default_value' => $item['name'],
    '#description' => t('The name of the filter.'),
    '#required' => TRUE,
  );
  $form['pattern'] = array(
    '#type' => 'textarea',
    '#title' => t('Pattern'),
    '#default_value' => $item['pattern'],
    '#description' => t('Regular expression. Look at <a href="http://www.regular-expressions.info">http://www.regular-expressions.info</a> for more help.'),
  );
  $form['replacement'] = array(
    '#type' => 'textarea',
    '#title' => t('Replacement text'),
    '#default_value' => $item['replacement'],
    '#description' => t('Replacement Text. Matched string will be replaced with text supplied here. Use $n (e.g. $1, $25) or ${n} (e.g. ${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 set the <strong>PHP Code</strong> below, you can enter replaced text with some PHP Code. n-th matched string will be provided in $matches[n], and there will be a global variable named $vars you can use it for your own purpose. Don\'t forget to write the return statement.'),
  );
  $form['func'] = array(
    '#type' => 'checkbox',
    '#title' => t('PHP Code'),
    '#default_value' => $item['func'],
    '#description' => t('Check to allow using PHP code to replace the text.'),
  );
  $form['weight'] = array(
    '#type' => 'weight',
    '#title' => t('Weight'),
    '#default_value' => $item['weight'],
    '#description' => t('Filter weight.'),
  );
  $form['description'] = array(
    '#type' => 'textarea',
    '#title' => t('Description'),
    '#default_value' => $item['description'],
    '#description' => t('Some text to describe this filter.'),
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save Configuration'),
  );
  return $form;
}