[ Index ]

PHP Cross Reference of Drupal 6 (gatewave)

title

Body

[close]

/sites/all/modules/features/theme/ -> theme.inc (source)

   1  <?php
   2  // $Id: theme.inc,v 1.1.2.24 2010/08/10 21:25:57 yhahn Exp $
   3  
   4  /**
   5   * Display feature component info
   6   */
   7  function template_preprocess_features_admin_components(&$vars) {
   8    drupal_add_css(drupal_get_path('module', 'features') .'/features.css');
   9    $form = $vars['form'];
  10  
  11    // Basic info
  12    $vars['name'] = $form['#info']['name'];
  13    $vars['description'] = isset($form['#info']['description']) ? $form['#info']['description'] : '';
  14  
  15    // Legend/key
  16    $vars['key'] = array();
  17  
  18    // Dependencies
  19    $rows = array();
  20    $modules = features_get_info();
  21    foreach ($form['#dependencies'] as $dependency => $status) {
  22      $rows[] = array(
  23        array(
  24          'data' => isset($modules[$dependency]->info['name']) ? $modules[$dependency]->info['name'] : $dependency,
  25          'class' => 'component'
  26        ),
  27        theme('features_module_status', $status),
  28      );
  29    }
  30    $vars['dependencies'] = theme('table', array(t('Dependency'), t('Status')), $rows);
  31  
  32    // Components
  33    $rows = array();
  34    $components = features_get_components();
  35    $conflicts = features_get_conflicts();
  36    if (!module_exists($form['module']['#value']) && isset($form['module']['#value']) && !empty($conflicts[$form['module']['#value']])) {
  37      $module_conflicts = $conflicts[$form['module']['#value']];
  38      $conflicts = array();
  39      foreach ($module_conflicts as $conflict) {
  40        $conflicts = array_merge_recursive($conflict, $conflicts);
  41      }
  42    }
  43    else {
  44      $conflicts = array();
  45    }
  46    // Display key for conflicting elements.
  47    if (!empty($conflicts)) {
  48      $vars['key'][] = array(
  49        'title' => theme('features_storage_link', FEATURES_CONFLICT, t('Conflicts with another feature')),
  50        'html' => TRUE,
  51      );
  52    }
  53  
  54    if (!empty($form['#info']['features'])) {
  55      foreach ($form['#info']['features'] as $component => $items) {
  56        if (!empty($items)) {
  57          $header = $data = array();
  58          if (element_children($form['revert'])) {
  59            $header[] = array(
  60              'data' => isset($form['revert'][$component]) ? drupal_render($form['revert'][$component]) : '',
  61              'header' => TRUE
  62            );
  63          }
  64          $header[] = array(
  65            'data' => isset($components[$component]['name']) ? $components[$component]['name'] : $component,
  66            'header' => TRUE
  67          );
  68          $header[] = array(
  69            'data' => drupal_render($form['components'][$component]),
  70            'header' => TRUE
  71          );
  72          $rows[] = $header;
  73  
  74          if (element_children($form['revert'])) {
  75            $data[] = '';
  76          }
  77          $component_conflicts = isset($conflicts[$component]) ? $conflicts[$component] : array();
  78          $data[] = array(
  79            'data' => theme('features_component_list', $items, $items, $component_conflicts),
  80            'colspan' => 2,
  81            'class' => 'component'
  82          );
  83          $rows[] = $data;
  84        }
  85      }
  86    }
  87    $vars['components'] = theme('table', array(), $rows);
  88  
  89    // Other elements
  90    $vars['buttons'] = drupal_render($form['buttons']);
  91    $vars['form'] = drupal_render($form);
  92  }
  93  
  94  /**
  95   * Preprocessor for theme('features_form').
  96   */
  97  function template_preprocess_features_form(&$vars) {
  98    drupal_add_css(drupal_get_path('module', 'features') .'/features.css');
  99    drupal_add_js(drupal_get_path('module', 'features') .'/features.js');
 100  
 101    $first = TRUE;
 102    $package_links = array();
 103    $packages = element_children($vars['form']);
 104    sort($packages);
 105    foreach ($packages as $package) {
 106      if (!empty($vars['form'][$package]['status'])) {
 107        $package_links[$package] = array(
 108          'title' => $vars['form'][$package]['#title'],
 109          'href' => $_GET['q'],
 110          'fragment' => $package,
 111        );
 112        $class = $first ? "$package features-package-active" : $package;
 113        $package_links[$package]['attributes'] = $first ? array('class' => 'features-package-active') : array();
 114        $vars['packages'][$class] = $vars['form'][$package];
 115  
 116        unset($vars['form'][$package]);
 117        $first = FALSE;
 118      }
 119    }
 120    $vars['package_links'] = $package_links;
 121  }
 122  
 123  /**
 124   * Themes a module status display.
 125   */
 126  function theme_features_module_status($status, $module = NULL) {
 127    switch ($status) {
 128      case FEATURES_MODULE_ENABLED:
 129        $text = !empty($module) ? $module : t('Enabled');
 130        return "<span class='admin-enabled'>{$text}</span>";
 131      case FEATURES_MODULE_DISABLED:
 132        $text = !empty($module) ? $module : t('Disabled');
 133        return "<span class='admin-disabled'>{$text}</span>";
 134      case FEATURES_MODULE_MISSING:
 135        $text = !empty($module) ? $module : t('Missing');
 136        return "<span class='admin-missing'>{$text}</span>";
 137    }
 138  }
 139  
 140  /**
 141   * Themes a module status display.
 142   */
 143  function theme_features_storage_link($storage, $text = NULL, $path = NULL, $options = array()) {
 144    $classes = array(
 145      FEATURES_OVERRIDDEN => 'admin-overridden',
 146      FEATURES_DEFAULT => 'admin-default',
 147      FEATURES_NEEDS_REVIEW => 'admin-needs-review',
 148      FEATURES_REBUILDING => 'admin-rebuilding',
 149      FEATURES_REBUILDABLE => 'admin-rebuilding',
 150      FEATURES_CONFLICT => 'admin-conflict',
 151      FEATURES_DISABLED => 'admin-disabled',
 152    );
 153    $default_text = array(
 154      FEATURES_OVERRIDDEN => t('Overridden'),
 155      FEATURES_DEFAULT => t('Default'),
 156      FEATURES_NEEDS_REVIEW => t('Needs review'),
 157      FEATURES_REBUILDING => t('Rebuilding'),
 158      FEATURES_REBUILDABLE => t('Rebuilding'),
 159      FEATURES_CONFLICT => t('Conflict'),
 160      FEATURES_DISABLED => t('Disabled'),
 161    );
 162    $text = isset($text) ? $text : $default_text[$storage];
 163    if ($path) {
 164      $options['attributes']['class'] = $classes[$storage] . ' features-storage';
 165      return l($text, $path, $options);
 166    }
 167    else {
 168      return "<span class='{$classes[$storage]} features-storage'>{$text}</span>";
 169    }
 170  }
 171  
 172  /**
 173   * Theme function for displaying form buttons
 174   */
 175  function theme_features_form_buttons($element) {
 176    drupal_add_css(drupal_get_path('module', 'features') .'/features.css');
 177  
 178    $output = drupal_render($element);
 179    return !empty($output) ? "<div class='buttons clear-block'>{$output}</div>" : '';
 180  }
 181  
 182  /**
 183   * Theme for features management form.
 184   */
 185  function theme_features_form_package($form) {
 186    drupal_add_css(drupal_get_path('module', 'features') .'/features.css');
 187    drupal_add_js(drupal_get_path('module', 'features') .'/features.js');
 188  
 189    $output = '';
 190  
 191    $header = array('', t('Feature'), t('Signature'));
 192    if (isset($form['state'])) {
 193      $header[] = t('State');
 194    }
 195    if (isset($form['actions'])) {
 196      $header[] = t('Actions');
 197    }
 198  
 199    $rows = array();
 200    foreach (element_children($form['status']) as $element) {
 201      // Yank title & description fields off the form element for
 202      // rendering in their own cells.
 203      $name = "<div class='feature'>";
 204      $name .= "<strong>{$form['status'][$element]['#title']}</strong>";
 205      $name .= "<div class='description'>{$form['status'][$element]['#description']}</div>";
 206      $name .= "</div>";
 207      unset($form['status'][$element]['#title']);
 208      unset($form['status'][$element]['#description']);
 209  
 210      // Determine row & cell classes
 211      $class = $form['status'][$element]['#default_value'] ? 'enabled' : 'disabled';
 212  
 213      $row = array(
 214        'status' => array('data' => drupal_render($form['status'][$element]), 'class' => 'status'),
 215        'name' => array('data' => $name, 'class' => 'name'),
 216        'sign' => array('data' => drupal_render($form['sign'][$element]), 'class' => 'sign'),
 217      );
 218      if (isset($form['state'])) {
 219        $row['state'] = array('data' => drupal_render($form['state'][$element]), 'class' => 'state');
 220      }
 221      if (isset($form['actions'])) {
 222        $row['actions'] = array('data' => drupal_render($form['actions'][$element]), 'class' => 'actions');
 223      }
 224      $rows[] = array('data' => $row, 'class' => $class);
 225    }
 226  
 227    if (empty($rows)) {
 228      $rows[] = array('', array('data' => t('No features available.'), 'colspan' => count($header)));
 229    }
 230  
 231    $class = count($header) > 3 ? 'features features-admin' : 'features features-manage';
 232    $output .= theme('table', $header, $rows, array('id' => 'features-form-table', 'class' => $class));
 233  
 234    // Prevent section from being rendered by drupal_render().
 235    unset($form['features']);
 236  
 237    $output .= drupal_render($form['buttons']);
 238    $output .= drupal_render($form);
 239    return $output;
 240  }
 241  
 242  /**
 243   * Theme functions ====================================================
 244   */
 245  
 246  /**
 247   * Export selection / display for features export form.
 248   */
 249  function theme_features_form_export($form) {
 250    drupal_add_css(drupal_get_path('module', 'features') .'/features.css');
 251    drupal_add_js(drupal_get_path('module', 'features') .'/features.js');
 252  
 253    $output = '';
 254    $output .= "<div class='clear-block features-components'>";
 255    $output .= "<div class='column'>". drupal_render($form['components']) . drupal_render($form['sources']) ."</div>";
 256    $output .= "<div class='column'>". drupal_render($form['features']) ."</div>";
 257    $output .= "</div>";
 258    $output .= drupal_render($form);
 259    return $output;
 260  }
 261  
 262  /**
 263   * Theme a set of features export components.
 264   */
 265  function theme_features_form_components($form) {
 266    $output = '';
 267    foreach (element_children($form) as $key) {
 268      unset($form[$key]['#title']);
 269      $output .= "<div class='features-select features-select-{$key}'>". drupal_render($form[$key]) ."</div>";
 270    }
 271    return $output;
 272  }
 273  
 274  /**
 275   * Theme a set of features export components.
 276   */
 277  function theme_features_components($info, $sources = array()) {
 278    $output = '';
 279    $rows = array();
 280    $components = features_get_components();
 281    if (!empty($info['features']) || !empty($info['dependencies']) || !empty($sources)) {
 282      $export = array_unique(array_merge(
 283        array_keys($info['features']),
 284        array_keys($sources),
 285        array('dependencies')
 286      ));
 287      foreach ($export as $component) {
 288        if ($component === 'dependencies') {
 289          $feature_items = isset($info[$component]) ? $info[$component] : array();
 290        }
 291        else {
 292          $feature_items = isset($info['features'][$component]) ? $info['features'][$component] : array();
 293        }
 294        $source_items = isset($sources[$component]) ? $sources[$component] : array();
 295        if (!empty($feature_items) || !empty($source_items)) {
 296          $rows[] = array(array(
 297            'data' => isset($components[$component]['name']) ? $components[$component]['name'] : $component,
 298            'header' => TRUE
 299          ));
 300          $rows[] = array(array(
 301            'data' => theme('features_component_list', $feature_items, $source_items),
 302            'class' => 'component'
 303          ));
 304        }
 305      }
 306      $output .= theme('table', array(), $rows);
 307      $output .= theme('features_component_key');
 308    }
 309    return $output;
 310  }
 311  
 312  /**
 313   * Theme individual components in a component list.
 314   */
 315  function theme_features_component_list($components, $source = array(), $conflicts = array()) {
 316    $list = array();
 317    foreach ($components as $component) {
 318      // If component is not in source list, it was autodetected
 319      if (!in_array($component, $source)) {
 320        $list[] = "<span class='features-detected'>". check_plain($component) ."</span>";
 321      }
 322      elseif (is_array($conflicts) && in_array($component, $conflicts)) {
 323        $list[] = "<span class='features-conflict'>". check_plain($component) ."</span>";
 324      }
 325      else {
 326        $list[] = "<span class='features-source'>". check_plain($component) ."</span>";
 327      }
 328    }
 329    foreach ($source as $component) {
 330      // If a source component is no longer in the items, it was removed because
 331      // it is provided by a dependency.
 332      if (!in_array($component, $components)) {
 333        $list[] = "<span class='features-dependency'>". check_plain($component) ."</span>";
 334      }
 335    }
 336    return "<span class='features-component-list'>". implode(' ', $list) ."</span>";
 337  }
 338  
 339  /**
 340   * Provide a themed key for a component list.
 341   */
 342  function theme_features_component_key() {
 343    $list = array();
 344    $list[] = "<span class='features-source'>" . t('Normal') . "</span>";
 345    $list[] = "<span class='features-detected'>" . t('Auto-detected') . "</span>";
 346    $list[] = "<span class='features-dependency'>" . t('Provided by dependency') . "</span>";
 347    return "<span class='features-component-list features-component-key'>". implode(' ', $list) ."</span>";
 348  }


Generated: Thu Mar 24 11:18:33 2011 Cross-referenced by PHPXref 0.7