You are here

function _cookie_content_blocker_variable_form in Cookie Content Blocker 7

Create a form based on variable information defined by a module.

Parameters

array $form: The structure of the form.

string $module: The module to look for a hook_variable_info() definition.

Return value

array The variable form, keyed by variable name.

2 calls to _cookie_content_blocker_variable_form()
cookie_content_blocker_media_settings_form in modules/cookie_content_blocker_media/cookie_content_blocker_media.admin.inc
Form callback for the admin settings form.
cookie_content_blocker_settings_form in ./cookie_content_blocker.admin.inc
Form callback for the admin settings form.

File

./cookie_content_blocker.module, line 488
Contains the main module code for Cookie content blocker.

Code

function _cookie_content_blocker_variable_form(array $form, $module) {
  module_load_include('variable.inc', $module);
  $variable_info = module_invoke($module, 'variable_info', array());
  if (empty($variable_info)) {
    return $form;
  }
  $type_map = array(
    'text' => 'textarea',
    'boolean' => 'checkbox',
    'string' => 'textfield',
  );
  foreach ($variable_info as $name => $info) {
    $current_value = variable_get($name, NULL);
    $element = isset($info['element']) ? $info['element'] : array();
    $element += array(
      '#type' => isset($type_map[$info['type']]) ? $type_map[$info['type']] : $info['type'],
      '#title' => $info['title'],
      '#description' => $info['description'],
      '#default_value' => $current_value === NULL ? $info['default'] : $current_value,
    );
    if (isset($info['options'])) {
      $element += array(
        '#options' => $info['options'],
      );
    }
    $form[$name] = $element;
  }
  return $form;
}