You are here

function _hosting_site_field in Hostmaster (Aegir) 6

Helper function to generate form elements for the site form.

2 calls to _hosting_site_field()
hosting_site_form in modules/hosting/site/hosting_site.form.inc
Implements hook_form().
hosting_ssl_site_form in modules/hosting/web_server/ssl/hosting_ssl.nodeapi.inc

File

modules/hosting/site/hosting_site.form.inc, line 10
Site node form.

Code

function _hosting_site_field(&$form, $node, $item, $element, $filter_display = 'filter_xss', $editable = FALSE, $show_desc = TRUE) {
  $css_id = str_replace("_", "-", $item);
  $type = $element['#type'];
  if (!$node->nid || $editable) {

    // create it
    if ($element['#type'] == 'radios' && !sizeof($element['#options'])) {
      $form[$item] = array(
        '#type' => 'hidden',
        '#value' => key($element['#options']),
      );
    }
    else {
      $form[$item] = $element;
    }
    if ($show_desc) {

      // the text to display when there are no valid options to select
      $form[$item . '_description'] = array(
        '#prefix' => "<div class='hosting-site-field-description' id='hosting-site-field-{$css_id}-description'>",
        '#suffix' => '</div>',
        '#type' => 'item',
        '#title' => $element['#title'],
        '#description' => $element['#description'],
        '#value' => "<div class='placeholder'>" . $filter_display($element['#default_value']) . "</div>",
      );
      if (isset($element['#weight'])) {
        $form[$item . '_description']['#weight'] = $element['#weight'];
      }
    }
  }
  else {
    $type = 'display';
    if ($show_desc) {

      // display it
      $form['info'][$item] = array(
        '#type' => 'item',
        '#title' => $element['#title'],
        '#value' => $filter_display($element['#default_value']),
        '#required' => FALSE,
      );
      if (isset($element['#weight'])) {
        $form['info'][$item]['#weight'] = $element['#weight'];
      }
    }
    $form[$item] = array(
      '#type' => 'hidden',
      '#value' => $element['#default_value'],
    );
  }
  $form[$item]['#hosting_site_field'] = $item;
  $form[$item]['#hosting_site_field_value'] = $element['#default_value'];
  $form[$item]['#prefix'] = "<div class='hosting-site-field hosting-site-field-{$type}' id='hosting-site-field-{$css_id}'>";
  $form[$item]['#suffix'] = "</div>";
}