You are here

function crossdomain_form in Crossdomain 7

Manages the domains for the crossdomain.xml file.

1 string reference to 'crossdomain_form'
crossdomain_menu in ./crossdomain.module
Implements hook_menu().

File

./crossdomain.admin.inc, line 6

Code

function crossdomain_form($form, &$form_state) {

  // Because we have many fields with the same values, we have to set
  // #tree to be able to access them.
  $form['#tree'] = TRUE;
  $form['domains_fieldset'] = array(
    '#type' => 'fieldset',
    '#title' => t('Domains to Allow For Flash Files'),
    // Set up the wrapper so that AJAX will be able to replace the fieldset.
    '#prefix' => '<div id="domains-fieldset-wrapper">',
    '#suffix' => '</div>',
  );
  $form['domains_fieldset']['description'] = array(
    '#markup' => 'Add domains that will be used to build a crossdomain.xml file so flash files can use it.',
  );

  // Get our current domains and set the number of domains.
  $domains = variable_get('crossdomain', array());
  if (empty($form_state['input']) && !empty($domains)) {
    $form_state['num_domains'] = count($domains);
  }
  else {
    if (!isset($form_state['num_domains'])) {
      $form_state['num_domains'] = 1;
    }
  }

  // Loop through all the current number of fields and build the form.
  for ($i = 0; $i < $form_state['num_domains']; $i++) {

    // Makes our fields inline so remove is next to the input field.
    $form['domains_fieldset']['element'][$i] = array(
      '#prefix' => '<div class="container-inline">',
      '#suffix' => '</div>',
    );

    // Field where the domain will be entered.
    $form['domains_fieldset']['element'][$i]['domain'] = array(
      '#type' => 'textfield',
    );
    if (empty($form_state['input']) && !empty($domains)) {
      $form['domains_fieldset']['element'][$i]['domain']['#default_value'] = $domains[$i];
    }
    if ($form_state['num_domains'] > 1) {
      $form['domains_fieldset']['element'][$i]['remove_button'] = array(
        '#type' => 'submit',
        '#value' => t('Remove'),
        '#name' => 'remove-button-' . $i,
        '#submit' => array(
          'crossdomain_form_remove_one',
        ),
        '#ajax' => array(
          'callback' => 'crossdomain_form_callback',
          'wrapper' => 'domains-fieldset-wrapper',
        ),
      );
    }
  }
  $form['domains_fieldset']['add_domain'] = array(
    '#type' => 'submit',
    '#value' => t('Add another'),
    '#submit' => array(
      'crossdomain_form_add_one',
    ),
    '#ajax' => array(
      'callback' => 'crossdomain_form_callback',
      'wrapper' => 'domains-fieldset-wrapper',
    ),
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Submit'),
  );
  return $form;
}