You are here

function dynamic_background_admin_weight_form in Dynamic Background 7

Same name and namespace in other branches
  1. 7.2 includes/weight.admin.inc \dynamic_background_admin_weight_form()

Creates a form which can be used to order the sub-modules/extension weights so the override order of the CSS can be weighted.

1 string reference to 'dynamic_background_admin_weight_form'
dynamic_background_menu in ./dynamic_background.module
Implements hook_menu().

File

includes/weight.admin.inc, line 13
Hanldes the re-ordring of dynamic background extension weights to determind overrid order.

Code

function dynamic_background_admin_weight_form($form_state) {
  $form = array(
    '#tree' => TRUE,
  );

  // Load default values.
  $default = variable_get('dynamic_background_weight', array());

  // Find all modules that implements hook_dynamic_background_weight().
  foreach (module_implements('dynamic_background_weight') as $module) {

    // Check if the weight have been overriden.
    $found = FALSE;
    foreach ($default as $value) {
      if ($value['name'] == $module) {
        $found = TRUE;
      }
    }
    if (!$found) {

      // Weight not found in defaults.
      $function = $module . '_dynamic_background_weight';
      $row = $function();
      $row['name'] = $module;
      $default[] = $row;
    }
  }

  // Sort the default values based on weight.
  usort($default, 'dynamic_background_weight_cmp');

  // Build the form based on the sorted values.
  foreach ($default as $module) {
    $form['module'][$module['name']] = array(
      // Module name
      'name' => array(
        '#markup' => ucfirst(str_replace('_', ' ', $module['name'])),
      ),
      // The weight of the module
      'weight' => array(
        '#type' => 'weight',
        '#delta' => 50,
        '#title-display' => 'invisible',
        '#default_value' => $module['weight'],
      ),
    );
  }
  $form['actions']['#type'] = 'actions';
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save configuration'),
  );
  return $form;
}