You are here

function context_prefix_form in Context 5

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

File

context_prefix/context_prefix.module, line 772

Code

function context_prefix_form($provider, $id, $prefix = '') {
  switch (variable_get('context_prefix_method_' . $provider, CONTEXT_PREFIX_PATH)) {
    case CONTEXT_PREFIX_PATH:
    case CONTEXT_PREFIX_PAIR:
      $description = t('Choose a prefix path. May contain only lowercase letters, numbers, dashes and underscores. e.g. "my-prefix"');
      break;
    case CONTEXT_PREFIX_SUBDOMAIN:
      $description = t('Enter a domain registered for this context, such as "mygroup".  Do not include http://');
      break;
    case CONTEXT_PREFIX_DOMAIN:
      $description = t('Enter a domain registered for this context, such as "www.example.com".  Do not include http://');
      break;
  }
  $form = array(
    '#tree' => TRUE,
    '#validate' => array(
      'context_prefix_form_validate' => array(),
    ),
  );
  $form['prefix'] = array(
    '#title' => t('Path prefix'),
    '#type' => 'textfield',
    '#description' => $description,
    '#maxlength' => 255,
    '#required' => true,
    '#default_value' => $prefix,
  );
  $form['provider'] = array(
    '#type' => 'value',
    '#value' => $provider,
  );
  $form['id'] = array(
    '#type' => 'value',
    '#value' => $id,
  );
  return $form;
}