Projet

Général

Profil

Paste
Télécharger (3,17 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / sweaver / sweaver.admin.inc @ 87dbc3bf

1
<?php
2

    
3
/**
4
 * @file
5
 * Administrative functions for sweaver plugins.
6
 */
7

    
8
/**
9
 * Plugins form.
10
 */
11
function sweaver_plugin_config_plugins() {
12
  $form = array();
13
  $weight = 100;
14
  $form['#tree'] = TRUE;
15
  $form['#plugins'] = array();
16
  $form['#theme'] = 'sweaver_plugin_config_plugins';
17
  $plugins_order = variable_get('sweaver_plugins_weight', array());
18
  cache_clear_all('plugins:sweaver:plugins', 'cache');
19
  cache_clear_all('sweaver_plugins', 'cache');
20
  drupal_add_css(drupal_get_path('module', 'sweaver') .'/sweaver_plugin.admin.css');
21

    
22
  $sweaver = Sweaver::get_instance();
23
  foreach ($sweaver->get_plugins_registry(FALSE) as $plugin_name => $plugin) {
24
    $sweaver_plugin = $sweaver->get_plugin($plugin_name, FALSE);
25

    
26
    $default_weight = isset($plugins_order[$plugin_name]) ? $plugins_order[$plugin_name] : $weight++;
27
    $form['#plugins'][$plugin_name] = $default_weight;
28

    
29
    // Status - editor can not be disabled.
30
    $status = variable_get('sweaver_plugin_status_'. $plugin_name, FALSE);
31
    if ($plugin_name == 'sweaver_plugin_editor') {
32
      $form[$plugin_name]['status'] = array(
33
        '#type' => 'checkbox',
34
        '#value' => 1,
35
        '#access' => FALSE,
36
      );
37
    }
38
    else {
39
      $missing = array();
40
      $can_be_enabled = TRUE;
41
      $dependencies = $sweaver_plugin->sweaver_dependencies();
42
      if (!empty($dependencies)) {
43
        foreach ($dependencies as $module) {
44
          if (!module_exists($module)) {
45
            $can_be_enabled = FALSE;
46
            $missing[] = $module;
47
          }
48
        }
49
      }
50
      $form[$plugin_name]['status'] = array(
51
          '#type' => 'checkbox',
52
          '#default_value' => $status,
53
      );
54
      if (!$can_be_enabled) {
55
        $form[$plugin_name]['status']['#disabled'] = TRUE;
56
        $form[$plugin_name]['status']['#value'] = 0;
57
        $form[$plugin_name]['status']['#description'] = t('Following modules or plugins are disabled or missing: @module', array('@module' => implode(', ', $missing)));
58
      }
59
    }
60

    
61
    // Markup.
62
    $form[$plugin_name]['name'] = array(
63
      '#markup' => isset($plugin['tab']) ? $plugin['tab'] : drupal_ucfirst($plugin_name),
64
    );
65
    $form[$plugin_name]['weight'] = array(
66
      '#type' => 'weight',
67
      '#delta' => 50,
68
      '#attributes' => array(
69
        'class' => array('plugin-weight'),
70
      ),
71
      '#default_value' => $default_weight,
72
    );
73
  }
74

    
75
  $form['submit'] = array(
76
    '#type' => 'submit',
77
    '#value' => t('Save configuration'),
78
  );
79

    
80
  return $form;
81
}
82

    
83
/**
84
 * Plugins form submit callback.
85
 */
86
function sweaver_plugin_config_plugins_submit(&$form, &$form_state) {
87
  // Reset cookies.
88
  setcookie('sweaver_active_tab', 'sweaver_plugin_editor');
89

    
90
  $plugins_order = array();
91
  foreach ($form['#plugins'] as $plugin_name => $weight) {
92
    variable_set('sweaver_plugin_status_'. $plugin_name, $form_state['values'][$plugin_name]['status']);
93
    $plugins_order[$plugin_name] = $form_state['values'][$plugin_name]['weight'];
94
  }
95
  variable_set('sweaver_plugins_weight', $plugins_order);
96
  drupal_flush_all_caches();
97
  variable_set('menu_rebuild_needed', TRUE);
98

    
99
  drupal_set_message(t('The configuration options have been saved.'));
100
  $form_state['redirect'] = 'admin/config/user-interface/sweaver/plugins';
101
}