diff --git a/libraries.admin.inc b/libraries.admin.inc
index e21847c..4d885f8 100644
--- a/libraries.admin.inc
+++ b/libraries.admin.inc
@@ -1,10 +1,26 @@
$header,
- 'rows' => $rows,
- 'empty' => t('There are currently no libraries installed'),
- ));
-
$form['libraries']['list'] = array(
- '#markup' => $table
+ '#theme' => 'table',
+ '#header' => $header,
+ '#rows' => $rows,
+ '#empty' => t('There are currently no libraries installed'),
);
return $form;
}
/**
- * Page callback for the status overview for a single library.
+ * Form generation callback for the status overview for a single library.
+ *
+ * This is a form instead of a page to allow easier extending in contributed
+ * modules.
+ *
+ * @param array $form
+ * An associative array containing the structure of the form.
+ * @param array $form_state
+ * A keyed array containing the current state of the form.
+ * @param string $name
+ * The name of the library to return the status report for.
+ *
+ * @return array|null
+ * The form array for the status form or NULL if the library was not found.
+ *
+ * @todo Add some var_export($library)-style output
*/
-function libraries_admin_library_status($name) {
- return drupal_get_form('libraries_admin_library_status_form', $name);
-}
-
-/**
- * Form page callback for the status overview for a single library.
- */
-function libraries_admin_library_status_form($form, $form_state, $name) {
- $output = '';
+function libraries_admin_library_status_form(array $form, array &$form_state, $name) {
$library = libraries_detect($name);
+
+ if ($library === FALSE) {
+ // @todo MENU_NOT_FOUND does not work here.
+ return;
+ }
+
drupal_set_title(t('Status report for library %library', array('%library' => $library['name'])), PASS_THROUGH);
if ($library['installed']) {
@@ -85,13 +111,17 @@ function libraries_admin_library_status_form($form, $form_state, $name) {
$rows[] = array('' . t('Variants') . '', implode(', ', array_keys($library['variants'])));
}
- $output = theme('table', array('header' => $header, 'rows' => $rows));
+ $form['status']['overview'] = array(
+ '#theme' => 'table',
+ '#header' => $header,
+ '#rows' => $rows,
+ );
}
else {
drupal_set_message($library['error message'], 'error');
switch ($library['error']) {
case 'not found':
- $output .= t('Follow the following steps to install the library:');
+ $form['status']['not_found']['instruction']['#markup'] = t('Follow these steps to install the library:');
$items = array();
// 1. Download the library.
// If no supported versions are specified, the latest version is
@@ -122,79 +152,60 @@ function libraries_admin_library_status_form($form, $form_state, $name) {
// 4. Upload it.
// If the library has variant-independent files, give the user the
// location of an example file to check his filesystem against.
- if (empty($library['files'])) {
- $items[] = t('Upload the whole library (which can consist of multiple directories) into the newly created %library-path directory.', array(
+ list($filepath, $file) = libraries_get_example_filepath($library);
+ if ($filepath !== FALSE) {
+ $items[] = t('Upload the whole library (which can consist of multiple directories) into the newly created %library-path directory. For example, the %file file, should be located at following filepath: %filepath', array(
'%library-path' => 'sites/all/libraries/' . $library['machine name'],
+ '%file' => $file,
+ '%filepath' => $filepath,
));
}
else {
- foreach (array('js', 'css', 'php') as $type) {
- if (!empty($library['files'][$type])) {
- $files = array_keys($library['files'][$type]);
- $filepath = $files[0];
- $parts = array_reverse(explode('/', $filepath));
- $file = $parts[0];
- $filepath = (!empty($library['path']) ? $library['path'] . '/' . $filepath : $filepath);
- $filepath = 'sites/all/libraries/' . $library['machine name'] . '/' . $filepath;
- }
- }
- $items[] = t('Upload the whole library (which can consist of multiple directories) into the newly created directory (%library-path). For example, the %file file, should be located at following filepath: %filepath', array(
+ $items[] = t('Upload the whole library (which can consist of multiple directories) into the newly created %library-path directory.', array(
'%library-path' => 'sites/all/libraries/' . $library['machine name'],
- '%file' => $file,
- '%filepath' => $filepath,
));
}
// 5. Reload.
$items[] = t('Reload the page. If successful, you should see status information about this library.');
- $output .= theme('item_list', array(
- 'items' => $items,
- 'type' => 'ol'
- ));
+ $form['status']['not_found']['steps'] = array(
+ '#theme' => 'item_list',
+ '#items' => $items,
+ '#type' => 'ol'
+ );
break;
case 'not detected':
// Re-check location.
// If the library has variant-independent files, give the user the
// location of an example file to check his filesystem against.
- if (empty($library['files'])) {
- $output .= t('Check that the whole library is located at %library-path.', array(
+ list($filepath, $file) = libraries_get_example_filepath($library);
+ if ($filepath !== FALSE) {
+ $form['status']['not_detected']['instruction']['#markup'] = t('Check that the whole library is located at %library-path. For example, the %file file, should be located at following filepath: %filepath', array(
'%library-path' => $library['library path'],
+ '%file' => $file,
+ '%filepath' => $filepath,
)) . '
';
}
else {
- foreach (array('js', 'css', 'php') as $type) {
- if (!empty($library['files'][$type])) {
- $files = array_keys($library['files'][$type]);
- $filepath = $files[0];
- $parts = array_reverse(explode('/', $filepath));
- $file = $parts[0];
- $filepath = (!empty($library['path']) ? $library['path'] . '/' . $filepath : $filepath);
- $filepath = 'sites/all/libraries/' . $library['machine name'] . '/' . $filepath;
- }
- }
- $output .= t('Check that the whole library is located at %library-path. For example, the %file file, should be located at following filepath: %filepath', array(
+ $form['status']['not_detected']['instruction']['#markup'] = t('Check that the whole library is located at %library-path.', array(
'%library-path' => $library['library path'],
- '%file' => $file,
- '%filepath' => $filepath,
)) . '
';
}
// If the library information was provided by a module, contact the maintainer.
+ // @todo Add support for themes by accessing $library['info type']
if (!empty($library['module'])) {
- $output .= t('If yes, the library information is corrupted. Contact the maintainer of the %module module with the following information:', array(
+ $form['status']['not_detected']['help']['#markup'] = t('If yes, the library information is corrupted. Contact the maintainer of the %module module with the following information:', array(
+ // @todo Use the human-readable module name instead.
'%module' => $library['module'],
)) . '
';
}
// Otherwise contact the author of the info file.
elseif (!empty($library['info file'])) {
- $output .= t("If yes, the library's info file (%info-file) is corrupted. Contact the author of this file with the following information:", array(
+ $form['status']['not_detected']['help']['#markup'] = t("If yes, the library's info file (%info-file) is corrupted. Contact the author of this file with the following information:", array(
'%info-file' => $library['info file'],
)) . '
';
}
- $output .= '
' . t('The version detection of the @name library failed. Library information:
@information', array( - '@name' => $library['machine name'], - '@information' => '' . var_export($library, TRUE) . '
', - )) . ''; break; case 'not supported': @@ -203,7 +214,7 @@ function libraries_admin_library_status_form($form, $form_state, $name) { usort($versions, 'version_compare'); $versions = array_reverse($versions); $version = $versions[0]; - $output .= t('Please install version %version of the library by following the following steps:', array( + $form['status']['not_supported']['instruction']['#markup'] = t('Please install version %version of the library by following the following steps:', array( '%version' => $version, )); // 1. Delete the old library. @@ -220,56 +231,78 @@ function libraries_admin_library_status_form($form, $form_state, $name) { // 4. Upload the new library. // If the library has variant-independent files, give the user the // location of an example file to check his filesystem against. - if (empty($library['files'])) { - $items[] = t('Upload the new files into the %library-path directory.', array( + list($filepath, $file) = libraries_get_example_filepath($library); + if ($filepath !== FALSE) { + $items[] = t('Upload the new files into the %library-path directory. For example, the %file file, should be located at following filepath: %filepath', array( '%library-path' => $library['library path'], + '%file' => $file, + '%filepath' => $filepath, )); } else { - foreach (array('js', 'css', 'php') as $type) { - if (!empty($library['files'][$type])) { - $files = array_keys($library['files'][$type]); - $filepath = $files[0]; - $parts = array_reverse(explode('/', $filepath)); - $file = $parts[0]; - $filepath = (!empty($library['path']) ? $library['path'] . '/' . $filepath : $filepath); - $filepath = $library['library path'] . '/' . $filepath; - } - } - $items[] = t('Upload the new files into the %library-path directory. For example, the %file file, should be located at following filepath: %filepath', array( + $items[] = t('Upload the new files into the %library-path directory.', array( '%library-path' => $library['library path'], - '%file' => $file, - '%filepath' => $filepath, )); } // 5. Reload. $items[] = t('Reload the page. If successful, you should see status information about this library.'); - $output .= theme('item_list', array( - 'items' => $items, - 'type' => 'ol' - )); + $form['status']['not_supported']['steps'] = array( + '#theme' => 'item_list', + '#items' => $items, + '#type' => 'ol', + ); // ...or contact the maintainer of the library information. // If the library information was provided by a module, contact the maintainer. + // @todo Add support for themes by accessing $library['info type'] if (!empty($library['module'])) { - $output .= t('If you are bound to the current version of the library, ask the maintainer of the %module module to provide support for version %version.', array( + $form['status']['not_supported']['help']['#markup'] = t('If you are bound to the current version of the library, ask the maintainer of the %module module to provide support for version %version.', array( + // @todo Use the human-readable module name instead. '%module' => $library['module'], '%version' => $library['version'], )) . '
'; } // Otherwise contact the author of the info file. elseif (!empty($library['info file'])) { - $output .= t("If you are bound to the current version of the library, ask the author of this library's info file (%info-file) to provide support for version %version", array( + $form['status']['not_supported']['help']['#markup'] = t("If you are bound to the current version of the library, ask the author of this library's info file (%info-file) to provide support for version %version", array( '%info-file' => $library['info file'], '%version' => $library['version'], )) . '
'; } break; + + // @todo Add a 'missing dependency' case. + // @todo Add a 'incompatible dependency' case. } } - $form['libraries']['status'] = array( - '#markup' => $output - ); - return $form; } + +/** + * Returns an example file path and file name from a library, if possible. + * + * The result of this function can help users to verify that they have uploaded + * the library to the correct location. + * + * @param array $library + * A library information array. + * + * @return array + * A list containing the example filepath and the example filename. If no + * example file was found, both entries will be FALSE. + */ +function libraries_get_example_filepath(array $library) { + $filepath = FALSE; + $file = FALSE; + foreach (array('js', 'css', 'php') as $type) { + if (!empty($library['files'][$type])) { + $files = array_keys($library['files'][$type]); + $filepath = $files[0]; + $parts = array_reverse(explode('/', $filepath)); + $file = $parts[0]; + $filepath = (!empty($library['path']) ? $library['path'] . '/' . $filepath : $filepath); + $filepath = 'sites/all/libraries/' . $library['machine name'] . '/' . $filepath; + } + } + return array($filepath, $file); +} diff --git a/libraries.module b/libraries.module index d81b408..3c7bf54 100644 --- a/libraries.module +++ b/libraries.module @@ -878,7 +878,7 @@ function libraries_get_version($library, $options) { function libraries_help($path, $arg) { switch ($path) { case 'admin/reports/libraries': - return t('Click on a library for a status report or, in case the library is not installed, detailed installation instructions.'); + return t('Click on a library for a status report or detailed installation instructions in case the library is not installed correctly.'); } } @@ -898,8 +898,8 @@ function libraries_menu() { $items['admin/reports/libraries/%'] = array( 'title' => 'Library status report', 'description' => 'Status overview for a single library', - 'page callback' => 'libraries_admin_library_status', - 'page arguments' => array(3), + 'page callback' => 'drupal_get_form', + 'page arguments' => array('libraries_admin_library_status_form', 3), 'access arguments' => array('access site reports'), 'file' => 'libraries.admin.inc' );