You are here

function finder_admin_element_edit in Finder 7

Same name and namespace in other branches
  1. 6 includes/finder.admin.inc \finder_admin_element_edit()

Admin finder element add/edit page. Must have a Finder object at this point.

2 string references to 'finder_admin_element_edit'
finder_i18nstrings_map_from_form in modules/finder_i18nstrings/finder_i18nstrings.module
Get a default map of which fields are translatable from the form.
finder_menu in ./finder.module
Implements hook_menu().

File

includes/finder.admin.inc, line 588
The finder admin screens.

Code

function finder_admin_element_edit($form, &$form_state, $finder, $finder_element_id) {
  $element =& finder_element($finder, $finder_element_id);

  // allow modules to change the element here
  finder_invoke_finderapi($element, 'finder_admin_element_edit', $form, $form_state);
  $module =& $finder->base_handler['#module'];
  $fields = module_invoke($module, 'finder_fields', $finder, $finder_element_id);
  $form_state['storage']['finder'] = $finder;
  $form_state['storage']['finder_element_id'] = $finder_element_id;
  $form_state['storage']['finder_element_defaults'] = $element;
  $form['#tree'] = TRUE;
  $form['finder_id'] = array(
    '#type' => 'value',
    '#value' => $finder->finder_id,
    '#weight' => 0,
  );
  $form['finder_element_id'] = array(
    '#type' => 'value',
    '#value' => $finder_element_id,
    '#weight' => 2,
  );
  $form['element'] = array(
    '#type' => 'select',
    '#title' => t('Element'),
    '#default_value' => $element->element ? $element->element : '',
    '#options' => finder_admin_get_element_options(),
    '#description' => t('The form element to use.'),
    '#required' => TRUE,
    '#weight' => 10,
  );
  $form['title'] = array(
    '#type' => 'textfield',
    '#title' => t('Title'),
    '#default_value' => $element->title ? $element->title : '',
    '#size' => 40,
    '#maxlength' => 255,
    '#required' => TRUE,
    '#weight' => 20,
    '#description' => t('The label on the form element.'),
  );
  $form['settings'] = array(
    '#weight' => 30,
  );
  $form['settings']['form'] = array(
    '#type' => 'fieldset',
    '#title' => t('Form element'),
    '#weight' => 0,
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['settings']['form']['description'] = array(
    '#type' => 'textfield',
    '#title' => t('Description'),
    '#default_value' => isset($element->settings['form']['description']) ? $element->settings['form']['description'] : '',
    '#weight' => 10,
    '#description' => t('The description or help message to display with the form element.'),
  );
  $form['settings']['form']['prefix'] = array(
    '#type' => 'text_format',
    '#base_type' => 'textarea',
    '#format' => isset($element->settings['form']['prefix']['format']) ? $element->settings['form']['prefix']['format'] : NULL,
    '#title' => t('Prefix'),
    '#default_value' => isset($element->settings['form']['prefix']['value']) ? $element->settings['form']['prefix']['value'] : '',
    '#weight' => 20,
    '#description' => t('Displayed before the form element.'),
  );
  $form['settings']['form']['suffix'] = array(
    '#type' => 'text_format',
    '#base_type' => 'textarea',
    '#format' => isset($element->settings['form']['suffix']['format']) ? $element->settings['form']['suffix']['format'] : NULL,
    '#title' => t('Suffix'),
    '#default_value' => isset($element->settings['form']['suffix']['value']) ? $element->settings['form']['suffix']['value'] : '',
    '#weight' => 30,
    '#description' => t('Displayed after the form element.'),
  );
  $form['settings']['form']['default_value'] = array(
    '#type' => 'textfield',
    '#title' => t('Default value'),
    '#default_value' => isset($element->settings['form']['default_value']) ? $element->settings['form']['default_value'] : '',
    '#weight' => 40,
    '#description' => t('Default value of the form element.'),
  );
  $form['settings']['form']['required'] = array(
    '#type' => 'checkbox',
    '#title' => t('Required'),
    '#default_value' => isset($element->settings['form']['required']) ? $element->settings['form']['required'] : 0,
    '#weight' => 50,
    '#description' => t('Enforce user input in this field.'),
  );
  $form['settings']['choices'] = array(
    '#type' => 'fieldset',
    '#title' => t('Possible choices'),
    '#weight' => 60,
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );
  if ($fields) {
    $form['settings']['choices']['field'] = array(
      '#type' => 'select',
      '#title' => t('Finder field'),
      '#default_value' => $element->settings['choices']['field'],
      '#options' => $fields,
      '#description' => t('This is the field that will be searched on (filtered).  If you pick multiple fields; performance will be affected.  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, using rewrite options below (if applicable), or through theming.'),
      '#weight' => 20,
      '#required' => TRUE,
      '#multiple' => TRUE,
      '#size' => min(12, count($fields) + 1),
    );
  }
  else {
    $form['settings']['choices']['no_field'] = array(
      '#markup' => t("<em>There are currently no fields to choose from.</em>"),
      '#weight' => 20,
    );
  }
  $form['settings']['choices']['sort'] = array(
    '#type' => 'checkbox',
    '#title' => t('Sort options'),
    '#default_value' => isset($element->settings['choices']['sort']) ? $element->settings['choices']['sort'] : 0,
    '#weight' => 100,
    '#description' => t('Will put the list into order for easier scanning.'),
  );
  $form['settings']['advanced'] = array(
    '#type' => 'fieldset',
    '#title' => t('Submitted values'),
    '#weight' => 500,
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['settings']['advanced']['delimit'] = array(
    '#type' => 'textfield',
    '#title' => t('Treat delimited values as separate keywords upon submission'),
    '#default_value' => isset($element->settings['advanced']['delimit']) ? $element->settings['advanced']['delimit'] : '',
    '#weight' => 10,
    '#description' => t('For example, if you type a space here, the submitted value will be expanded into a value for each word.  Leave empty to disable this feature.'),
  );
  $form['settings']['advanced']['field_combination'] = array(
    '#type' => 'radios',
    '#title' => t('Multiple field result combination'),
    '#default_value' => isset($element->settings['advanced']['field_combination']) ? $element->settings['advanced']['field_combination'] : 0,
    '#weight' => 20,
    '#description' => t('With multiple fields being select above, how should the fields be combined when calculating results?'),
    '#options' => array(
      // I know these choices are in a different order than on the finder admin
      // page, but that's because the first option is the more appropriate
      // default in both cases.
      0 => t('<em>Disjunction</em> - Match <em>any</em> field using the OR operator.'),
      1 => t('<em>Conjunction</em> - Match <em>all</em> fields using the AND operator.'),
    ),
  );
  $form['settings']['advanced']['value_combination'] = array(
    '#type' => 'radios',
    '#title' => t('Multiple value result combination'),
    '#default_value' => isset($element->settings['advanced']['value_combination']) ? $element->settings['advanced']['value_combination'] : 0,
    '#weight' => 25,
    '#description' => t('With multiple submitted values for this element, how should the values be combined when calculating results?'),
    '#options' => array(
      // I know these choices are in a different order than on the finder admin
      // page, but that's because the first option is the more appropriate
      // default in both cases.
      0 => t('<em>Disjunction</em> - Match <em>any</em> value using the OR operator.'),
      1 => t('<em>Conjunction</em> - Match <em>all</em> values using the AND operator.'),
    ),
  );
  $form['settings']['advanced']['nesting_order'] = array(
    '#type' => 'radios',
    '#title' => t('Multiple field/value nesting order'),
    '#default_value' => isset($element->settings['advanced']['nesting_order']) ? $element->settings['advanced']['nesting_order'] : 0,
    '#weight' => 30,
    '#description' => t('With multiple values or fields, how should fields and values be matched together?  This is difficult to explain.  Suppose you have an element that selects two fields and a user submits two values (X and Y), the first option here will do matching like this: <em>(field_1 matches X; field_2 matches X), (field_1 matches Y; field_2 matches Y)</em> whereas the second will do it like this: <em>(field_1 matches X, field_1 matches Y); (field_2 matches X, field_2 matches Y)</em>.  The semicolons represent <em>multiple field result combination</em>, the commas represent <em>multiple value result combination</em>, and the word <em>matches</em> refers to the <em>result matching</em> option below.  So simple.'),
    '#options' => array(
      0 => t('Match multiple fields for each value first, then combine the results of multiple values. (recommended)'),
      1 => t('Match multiple values for each field first, then combine the results of multiple fields.'),
    ),
  );
  $operators = finder_condition_args();
  foreach ($operators as $k => $v) {
    $operators[$k] = finder_condition_args_label($v, t('results'), t('submitted values'));
  }
  $form['settings']['advanced']['match'] = array(
    '#type' => 'radios',
    '#title' => t('Result matching'),
    '#default_value' => isset($element->settings['advanced']['match']) ? $element->settings['advanced']['match'] : 'e',
    '#options' => $operators,
    '#weight' => 60,
    '#description' => t('<em>Equals</em> is the most common result matching method. <a href="!url">Configure custom matching</a>.', array(
      '!url' => url('admin/structure/finder/custom_matching'),
    )),
  );
  $form['actions'] = array(
    '#type' => 'actions',
    '#weight' => 100,
  );
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save finder element'),
  );
  $form['actions']['delete'] = array(
    '#type' => 'submit',
    '#value' => t('Delete finder element'),
  );
  $form['actions']['cancel'] = array(
    '#markup' => l(t('Cancel'), 'admin/structure/finder/' . $finder->finder_id . '/' . $finder_element_id),
  );
  return $form;
}