You are here

function theme_spaces_features_form in Spaces 6.2

Same name and namespace in other branches
  1. 5.2 spaces_admin.inc \theme_spaces_features_form()
  2. 5 spaces_admin.inc \theme_spaces_features_form()
  3. 6.3 spaces.theme.inc \theme_spaces_features_form()
  4. 6 spaces_admin.inc \theme_spaces_features_form()

Theme for spaces featuers/settings form. @TODO: this could probably live in a preprocess/template file.

File

./spaces.theme.inc, line 126

Code

function theme_spaces_features_form($form) {
  drupal_add_css(drupal_get_path('module', 'features') . '/features.css');
  drupal_add_css(drupal_get_path('module', 'spaces') . '/spaces.css');
  drupal_add_js(drupal_get_path('module', 'spaces') . '/spaces.js');

  // Add draggable weights
  drupal_add_js('misc/tableheader.js');
  drupal_add_tabledrag('spaces-features', 'order', 'sibling', 'feature-weight');
  $output = '';
  foreach (array(
    'features',
    'settings',
  ) as $type) {
    $header = array(
      t('Settings'),
      array(
        'class' => 'action',
        'data' => !isset($form['space']['#value']->sid) ? t('Locked') : '',
      ),
      '',
    );
    if ($type == 'features') {
      $header[0] = t('Features');
      $header[] = '';
    }
    $rows = array();
    foreach (element_children($form[$type]) as $element) {

      // Yank title & description fields off the form element for
      // rendering in their own cells.
      $feature_name = "<strong>{$form[$type][$element]['#title']}</strong>";
      $feature_name .= "<div class='description'>{$form[$type][$element]['#description']}</div>";
      $feature_name = "<div class='feature'>{$feature_name}</div>";
      unset($form[$type][$element]['#title']);
      unset($form[$type][$element]['#description']);
      $row = array(
        'name' => $feature_name,
        'action' => drupal_render($form['customize'][$element]) . drupal_render($form['locked'][$type][$element]),
        'option' => drupal_render($form[$type][$element]),
      );

      // Determine row classes
      $class = '';
      if ($type == 'features') {
        $class = $form[$type][$element]['#default_value'] ? 'enabled' : 'disabled';
      }
      $class .= !empty($form[$type][$element]['#locked']) ? ' locked' : '';

      // Add feature weighting
      if ($type == 'features') {
        $form['weights'][$element]['#attributes'] = array(
          'class' => 'feature-weight',
        );
        $row['weight'] = drupal_render($form['weights'][$element]);
        $class .= ' draggable';
      }

      // Collect data + classes & add to master array.
      foreach ($row as $key => $data) {
        $row[$key] = array(
          'data' => $data,
          'class' => $key,
        );
      }
      $rows[] = array(
        'data' => $row,
        'class' => $class,
      );
    }
    if (!empty($rows)) {
      $output .= theme('table', $header, $rows, array(
        'id' => 'spaces-' . $type,
        'class' => 'features spaces-' . $type,
      ));
    }

    // Prevent section from being rendered by drupal_render().
    unset($form[$type]);
  }
  $output .= drupal_render($form['buttons']);
  $output .= drupal_render($form);
  return $output;
}