You are here

function purl_form in Persistent URL 6

Same name and namespace in other branches
  1. 7 purl.module \purl_form()

Generates a persistent url form element that can be dropped into a FormAPI form array. Includes validation, but insert/update must be handled by the implementing submit handler.

File

./purl.module, line 698

Code

function purl_form($provider, $id, $value = '', $required = TRUE) {
  $method = variable_get('purl_method_' . $provider, 'path');
  $processor = purl_get_processor($method);
  $form = array(
    '#tree' => TRUE,
    '#element_validate' => array(
      'purl_form_validate',
    ),
  );
  $processors = _purl_options();
  global $base_url;
  $form['value'] = array(
    '#title' => isset($processors[$method]) ? $processors[$method] : '',
    '#type' => 'textfield',
    '#description' => $processor
      ->description(),
    '#size' => 20,
    '#maxlength' => 255,
    '#required' => $required,
    '#default_value' => $value,
    '#field_prefix' => $method == 'path' ? $base_url . '/' : NULL,
  );
  $form['provider'] = array(
    '#type' => 'value',
    '#value' => $provider,
  );
  $form['id'] = array(
    '#type' => 'value',
    '#value' => $id,
  );
  return $form;
}