Projet

Général

Profil

Révision ed912c77

Ajouté par Assos Assos il y a presque 6 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/libraries/libraries.admin.inc
20 20
 *   The form array for the overview form.
21 21
 */
22 22
function libraries_admin_overview(array $form, array &$form_state) {
23
  $header = array(t('Name'), t('Status'), t('Installed version'), t('Provider'), t('Links'));
24
  $rows = array();
25

  
26
  $libraries = libraries_detect();
27
  uasort($libraries, 'libraries_admin_sort_title');
28

  
29
  foreach ($libraries as $machine_name => $library) {
23
  // Only show variants for installed libraries.
24
  $header_installed = array(t('Name'), t('Version'), t('Variants'), t('Dependencies'), t('Provider'), t('Links'));
25
  // Only show status for libraries with an error.
26
  $header_error = array(t('Name'), t('Status'), t('Version'), t('Dependencies'), t('Provider'), t('Links'));
27
  // For unregistered libraries the only information we can show is the path.
28
  $header_unregistered = array(t('Name'), t('Path'));
29

  
30
  $rows_installed = array();
31
  $rows_error = array();
32
  $rows_unregistered = array();
33

  
34
  // Registered libraries: we prefer to use libraries_detect() since it provides
35
  // library metadata.
36
  $libraries_registered = libraries_detect();
37
  uasort($libraries_registered, 'libraries_admin_sort_title');
38

  
39
  // Unregistered libraries: modules can depend on Libraries API without sharing
40
  // metadata by using libraries_get_path(). Libraries can also be placed in the
41
  // filesystem that are incorrectly installed, a wrong version, or a standalone
42
  // not connected to any module. In these cases, libraries_get_libraries()
43
  // provides a full library list. Libraries found by libraries_get_libraries(),
44
  // but not identified by libraries_detect, are displayed in a separate table.
45
  $libraries_unregistered = libraries_get_libraries();
46
  natcasesort($libraries_unregistered);
47

  
48
  foreach ($libraries_registered as $machine_name => $library) {
30 49
    $actions = array();
50
    $row = array();
31 51

  
32 52
    if ($library['vendor url']) {
33
      $actions[] = l('Homepage', $library['vendor url']);
53
      $actions[] = l(t('Homepage'), $library['vendor url']);
34 54
    }
35 55
    if ($library['download url']) {
36
      $actions[] = l('Download', $library['download url']);
56
      $actions[] = l(t('Download'), $library['download url']);
57
    }
58

  
59
    $row['data'][] = l($library['name'], 'admin/reports/libraries/' . $machine_name);
60
    // Only show status for libraries with an error. See above.
61
    if (!$library['installed']) {
62
      $row['data'][] = drupal_ucfirst($library['error']);
63
    }
64
    $row['data'][] = isset($library['version']) ? $library['version'] : '';
65
    if ($library['installed']) {
66
      $row['data'][] = implode(', ', array_keys($library['variants']));
67
    }
68
    $row['data'][] = libraries_admin_get_dependencies($library);
69
    $row['data'][] = libraries_admin_get_provider_with_type($library);
70
    $row['data'][] = implode(' | ', $actions);
71
    $row['class'] = $library['installed'] ? array('ok') : array('warning');
72

  
73
    if ($library['installed']) {
74
      $rows_installed[] = $row;
37 75
    }
76
    else {
77
      $rows_error[] = $row;
78
    }
79

  
80
    // Filter registered libraries from unregistered libraries.
81
    unset($libraries_unregistered[$library['machine name']]);
82
  }
83

  
84
  // Build table of registered libraries with installed status.
85
  $form['libraries']['installed'] = array(
86
    '#theme' => 'libraries_table_with_title',
87
    '#title' => t('Installed'),
88
    '#header' => $header_installed,
89
    '#rows' => $rows_installed,
90
    '#description' => t('These libraries are registered and installed correctly.'),
91
    '#empty' => t('There are currently no libraries that are registered and installed.'),
92
  );
93

  
94
  // Build table of registered libraries with error status.
95
  $form['libraries']['error'] = array(
96
    '#theme' => 'libraries_table_with_title',
97
    '#title' => t('Uninstalled'),
98
    '#header' => $header_error,
99
    '#rows' => $rows_error,
100
    '#description' => t('These libraries are registered but not installed. They may not need to be installed in case a module or theme provides optional integration with a library.'),
101
    '#empty' => t('There are currently no libraries that are registered but not installed.'),
102
  );
38 103

  
39
    $rows[] = array(
104
  // Build table of unregistered libraries.
105
  foreach ($libraries_unregistered as $name => $path) {
106
    $rows_unregistered[] = array(
40 107
      'data' => array(
41
        l($library['name'], 'admin/reports/libraries/' . $machine_name),
42
        ($library['installed'] ? t('OK') : drupal_ucfirst($library['error'])),
43
        (isset($library['version']) ? $library['version'] : ''),
44
        libraries_admin_get_provider_with_type($library),
45
        implode(' | ', $actions),
108
        $name,
109
        $path,
46 110
      ),
47
      'class' => ($library['installed'] ? array('ok') : array('error')),
48 111
    );
49 112
  }
50

  
51
  $form['libraries']['list'] = array(
52
    '#theme' => 'table',
53
    '#header' => $header,
54
    '#rows' => $rows,
55
    '#empty' => t('There are currently no libraries installed'),
113
  $form['libraries']['unregistered'] = array(
114
    '#theme' => 'libraries_table_with_title',
115
    '#title' => t('Unregistered'),
116
    '#header' => $header_unregistered,
117
    '#rows' => $rows_unregistered,
118
    '#description' => t('These libraries were found in the filesystem but there is no metadata about them.'),
119
    // Do not show the table at all, if there are no unregistered libraries.
120
    '#access' => (bool) $libraries_unregistered,
56 121
  );
57 122

  
123
  // Clear the cached library information so that the library can be loaded if
124
  // it was just downloaded. Because these instructions use libraries_detect()
125
  // directly, they will never use the cached information, but this avoids the
126
  // overview showing a library as installed but it not being loadable.
127
  libraries_cache_clear();
128

  
58 129
  return $form;
59 130
}
60 131

  
......
99 170
        break;
100 171

  
101 172
      case 'missing dependency':
102
        $form['instructions']['instruction']['#markup'] = t('There a missing dependency in your configuration that prevent this library to work properly.') . '<br>';
173
        $form['instructions']['instruction']['#markup'] = t('There is a missing dependency in your configuration that prevents this library from working properly.') . '<br>';
103 174
        break;
104 175

  
105 176
      case 'incompatible dependency':
106
        $form['instructions']['instruction']['#markup'] = t('There an incompatible dependency in your configuration that prevent this library to work properly.') . '<br>';
177
        $form['instructions']['instruction']['#markup'] = t('There is an incompatible dependency in your configuration that prevents this library from working properly.') . '<br>';
107 178
        break;
108 179
    }
109 180
  }
......
483 554
  return strnatcasecmp($a['name'], $b['name']);
484 555
}
485 556

  
557
/**
558
 * Returns the library's dependencies, if any.
559
 *
560
 * @param array $library
561
 *   A library information array.
562
 *
563
 * @return string
564
 *   The dependencies.
565
 */
566
function libraries_admin_get_dependencies($library) {
567
  $dependencies = array();
568
  foreach ($library['dependencies'] as $dependency_name) {
569
    if ($dependency = libraries_info($dependency_name)) {
570
      $dependencies[] = $dependency['name'];
571
    }
572
    else {
573
      $dependencies[] = $dependency_name;
574
    }
575
  }
576
  return implode(', ', $dependencies);
577
}
578

  
486 579
/**
487 580
 * Returns the library's provider.
488 581
 *

Formats disponibles : Unified diff