You are here

function libraries_admin_overview in Libraries API 7.2

Form generation callback for the libraries overview table.

This is a form instead of a page to allow easier extending in contributed modules.

Parameters

array $form: An associative array containing the structure of the form.

array $form_state: A keyed array containing the current state of the form.

Return value

array The form array for the overview form.

1 string reference to 'libraries_admin_overview'
libraries_menu in ./libraries.module
Implements hook_menu().

File

./libraries.admin.inc, line 22
Provides administrative page and form callbacks for Libraries module.

Code

function libraries_admin_overview(array $form, array &$form_state) {

  // Only show variants for installed libraries.
  $header_installed = array(
    t('Name'),
    t('Version'),
    t('Variants'),
    t('Dependencies'),
    t('Provider'),
    t('Links'),
  );

  // Only show status for libraries with an error.
  $header_error = array(
    t('Name'),
    t('Status'),
    t('Version'),
    t('Dependencies'),
    t('Provider'),
    t('Links'),
  );

  // For unregistered libraries the only information we can show is the path.
  $header_unregistered = array(
    t('Name'),
    t('Path'),
  );
  $rows_installed = array();
  $rows_error = array();
  $rows_unregistered = array();

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

  // Unregistered libraries: modules can depend on Libraries API without sharing
  // metadata by using libraries_get_path(). Libraries can also be placed in the
  // filesystem that are incorrectly installed, a wrong version, or a standalone
  // not connected to any module. In these cases, libraries_get_libraries()
  // provides a full library list. Libraries found by libraries_get_libraries(),
  // but not identified by libraries_detect, are displayed in a separate table.
  $libraries_unregistered = libraries_get_libraries();
  natcasesort($libraries_unregistered);
  foreach ($libraries_registered as $machine_name => $library) {
    $actions = array();
    $row = array();
    if ($library['vendor url']) {
      $actions[] = l(t('Homepage'), $library['vendor url']);
    }
    if ($library['download url']) {
      $actions[] = l(t('Download'), $library['download url']);
    }
    $row['data'][] = l($library['name'], 'admin/reports/libraries/' . $machine_name);

    // Only show status for libraries with an error. See above.
    if (!$library['installed']) {
      $row['data'][] = drupal_ucfirst($library['error']);
    }
    $row['data'][] = isset($library['version']) ? $library['version'] : '';
    if ($library['installed']) {
      $row['data'][] = implode(', ', array_keys($library['variants']));
    }
    $row['data'][] = libraries_admin_get_dependencies($library);
    $row['data'][] = libraries_admin_get_provider_with_type($library);
    $row['data'][] = implode(' | ', $actions);
    $row['class'] = $library['installed'] ? array(
      'ok',
    ) : array(
      'warning',
    );
    if ($library['installed']) {
      $rows_installed[] = $row;
    }
    else {
      $rows_error[] = $row;
    }

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

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

  // Build table of registered libraries with error status.
  $form['libraries']['error'] = array(
    '#theme' => 'libraries_table_with_title',
    '#title' => t('Uninstalled'),
    '#header' => $header_error,
    '#rows' => $rows_error,
    '#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.'),
    '#empty' => t('There are currently no libraries that are registered but not installed.'),
  );

  // Build table of unregistered libraries.
  foreach ($libraries_unregistered as $name => $path) {
    $rows_unregistered[] = array(
      'data' => array(
        $name,
        $path,
      ),
    );
  }
  $form['libraries']['unregistered'] = array(
    '#theme' => 'libraries_table_with_title',
    '#title' => t('Unregistered'),
    '#header' => $header_unregistered,
    '#rows' => $rows_unregistered,
    '#description' => t('These libraries were found in the filesystem but there is no metadata about them.'),
    // Do not show the table at all, if there are no unregistered libraries.
    '#access' => (bool) $libraries_unregistered,
  );

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