You are here

function template_preprocess_spaces_overrides_form in Spaces 7.3

Same name and namespace in other branches
  1. 7 theme/theme.inc \template_preprocess_spaces_overrides_form()

Preprocessor for theme('spaces_overrides_form').

File

theme/theme.inc, line 106

Code

function template_preprocess_spaces_overrides_form(&$variables) {
  drupal_add_js(drupal_get_path('module', 'spaces') . '/spaces.js');
  drupal_add_css(drupal_get_path('module', 'spaces') . '/spaces.css');
  drupal_add_js('misc/tableselect.js');
  $form =& $variables['form'];
  $header = array(
    array(
      'class' => array(
        'select-all',
      ),
      'colspan' => 1,
    ),
    array(
      'data' => t('Type'),
      'colspan' => 1,
    ),
    array(
      'data' => t('Override value'),
      'colspan' => 2,
    ),
  );
  $rows = array();
  foreach (array_keys(spaces_controllers()) as $controller) {
    if (!empty($form[$controller])) {
      foreach (element_children($form[$controller]) as $key) {
        $label = $form[$controller][$key]['#title'];
        $value = $form[$controller][$key]['#description'];
        $inherited = !empty($form[$controller][$key]['#disabled']);
        unset($form[$controller][$key]['#title'], $form[$controller][$key]['#description']);
        $row = array(
          'data' => array(
            array(
              'class' => array(
                'option',
              ),
              'data' => $form[$controller][$key],
            ),
            array(
              'class' => array(
                'controller',
              ),
              'data' => $controller,
            ),
            array(
              'class' => array(
                'key',
              ),
              'data' => l($label, $_GET['q'], array(
                'fragment' => $key,
              )) . '<span class="override-value"><pre>' . $value . '</pre></span>',
              'colspan' => $inherited ? 1 : 2,
            ),
          ),
        );
        if ($inherited) {
          $row['class'] = array(
            'inherited',
          );
          $row['data'][] = array(
            'class' => array(
              'tag',
            ),
            'data' => t('inherited'),
          );
        }
        $rows[] = $row;
      }
    }
    unset($form[$controller]);
  }
  if (count($rows)) {
    if (isset($form['preset'])) {
      $preset_label = $form['preset']['#title'];
      unset($form['preset']['#title']);
      $rows[] = array(
        array(
          'data' => $preset_label,
          'class' => array(
            'action-label',
          ),
          'colspan' => 2,
        ),
        array(
          'data' => $form['preset'],
          'class' => array(
            'action-form',
          ),
          'colspan' => 3,
        ),
      );
      unset($form['preset']);
    }
    if (isset($form['revert'])) {
      $revert_label = $form['revert']['#title'];
      unset($form['revert']['#title']);
      $rows[] = array(
        array(
          'data' => $revert_label,
          'class' => array(
            'action-label',
          ),
          'colspan' => 2,
        ),
        array(
          'data' => $form['revert'],
          'class' => array(
            'action-form',
          ),
          'colspan' => 3,
        ),
      );
      unset($form['revert']);
    }
  }
  else {
    $rows[] = array(
      array(
        'data' => t('No overrides present.'),
        'colspan' => 5,
      ),
    );
  }
  $table = array(
    'header' => $header,
    'rows' => $rows,
    'attributes' => array(
      'class' => array(
        'spaces',
      ),
    ),
  );
  $variables['overrides'] = theme('table', $table);
}