You are here

function finder_ui_field_form in Finder 7.2

Finder UI field form.

Parameters

$form: The form array.

$form_state: The form state array.

Return value

The form array.

1 string reference to 'finder_ui_field_form'
finder_ui_field_page in modules/finder_ui/includes/field.inc
Finder UI field page.

File

modules/finder_ui/includes/field.inc, line 101

Code

function finder_ui_field_form($form, &$form_state) {
  $feid =& $form_state['feid'];
  $finder =& $form_state['finder'];
  $field_key =& $form_state['field_key'];
  $element =& $finder->elements[$feid];
  $relationships = $finder
    ->relationships();
  if ($field_key == 'new') {
    $fields = $finder
      ->fields(FALSE, FALSE);
    if ($fields) {
      $field_options = array();
      foreach ($fields as $key => $value) {
        $field_options[$key] = $value['group'] . ': ' . $value['title'] . '<div class="description">' . $value['help'] . '</div>';
      }
      $form['field'] = array(
        '#type' => 'radios',
        '#title' => t('Field'),
        '#options' => $field_options,
        '#description' => t('This is the field that will be searched on (filtered).  This field will also be displayed in choices lists (if applicable), however often the raw values of this field are unacceptable for human readability, you can overcome this with PHP by using a computed field, or using the <em>rewrite choices</em> setting on the finder element.'),
        '#required' => TRUE,
      );
    }
    else {
      $form['no_fields']['#markup'] = t('There are no fields to choose from.');
    }
  }
  else {
    $form['field'] = array(
      '#type' => 'hidden',
      '#default_value' => $field_key,
    );
  }
  if (!empty($relationships)) {
    $form['relationship'] = array(
      '#type' => 'select',
      '#title' => t('Relationship'),
      '#options' => array_merge(array(
        ' - ' . t('Select if applicable') . ' - ',
      ), $relationships),
      '#description' => t('If your views display requires a relationship to use this field, specify it here.'),
      '#default_value' => !empty($field->relationship) ? $field->relationship : NULL,
    );
  }
  $form['sanitization'] = array(
    '#type' => 'fieldset',
    '#title' => t('Sanitization'),
    '#description' => t('No piece of user-submitted content should ever be placed as-is into HTML.'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $format_options = array(
    'filter_xss' => t('Filter XSS') . theme('filter_tips', array(
      'tips' => array(
        array(
          array(
            'tip' => t('Filters HTML to prevent cross-site-scripting (XSS) vulnerabilities.'),
          ),
          array(
            'tip' => t('Allowed HTML tags') . check_plain(': <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>'),
          ),
          array(
            'tip' => '<strong>' . t('Recommended for finder fields that contain only plain values or the above HTML tags.') . '</strong>',
          ),
        ),
      ),
    ), FALSE),
    'filter_xss_admin' => t('Filter XSS permissive') . theme('filter_tips', array(
      'tips' => array(
        array(
          array(
            'tip' => t('Allows all tags that can be used inside an HTML body, save for scripts and styles.'),
          ),
          array(
            'tip' => '<strong>' . t('Recommended for finder fields that contain HTML.') . '</strong>',
          ),
        ),
      ),
    ), FALSE),
    'check_plain' => t('Check plain') . theme('filter_tips', array(
      'tips' => array(
        array(
          array(
            'tip' => t('Encodes special characters in a plain-text string for display as HTML.'),
          ),
          array(
            'tip' => '<strong>' . t('Approved for finder fields that contain only plain values.') . '</strong>',
          ),
        ),
      ),
    ), FALSE),
    'check_url' => t('Check URL') . theme('filter_tips', array(
      'tips' => array(
        array(
          array(
            'tip' => t('Strips dangerous protocols from a URI and encodes it for output to HTML.'),
          ),
          array(
            'tip' => '<strong>' . t('Approved for finder fields where the value is a URL.') . '</strong>',
          ),
        ),
      ),
    ), FALSE),
    'strip_tags' => t('Strip Tags') . theme('filter_tips', array(
      'tips' => array(
        array(
          array(
            'tip' => t('Strips HTML tags.'),
          ),
          array(
            'tip' => '<strong>' . t('Approved for finder fields that contain undesired HTML.') . '</strong>',
          ),
        ),
      ),
    ), FALSE),
  );
  $filter_formats = filter_formats();
  foreach ($filter_formats as $filter_format) {
    $tips = _filter_tips($filter_format->format, FALSE);
    $tips[$filter_format->name]['finder'] = array(
      'tip' => t('Not pre-approved for finder fields, use with caution.'),
    );
    $format_options[$filter_format->format] = $filter_format->name . theme('filter_tips', array(
      'tips' => $tips,
    ));
  }
  $form['sanitization']['format'] = array(
    '#type' => 'radios',
    '#title' => t('Sanitization filter'),
    '#default_value' => !empty($field->format) ? $field->format : 'filter_xss',
    '#options' => $format_options,
  );

  //if ($field_key != 'new' && empty($relationships)) {

  //  $form['no_config']['#markup'] = t('There is nothing to configure for this field.');

  //}

  // Add buttons.
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Apply'),
  );
  $form['actions']['delete'] = array(
    '#type' => 'submit',
    '#value' => t('Remove'),
  );
  $form['actions']['cancel'] = array(
    '#type' => 'submit',
    '#value' => t('Cancel'),
  );
  $form['#pre_render'] = array(
    'finder_ui_modal_form_pre_render',
  );
  return $form;
}