You are here

function _acquia_lift_missing_library_warning in Acquia Lift Connector 7.2

Same name and namespace in other branches
  1. 7 acquia_lift.module \_acquia_lift_missing_library_warning()

Helper function to display a message when a missing library is detected.

This can provide targeted messaging on pages that require a JavaScript library in order to be useful.

Parameters

$required_libraries: An array of required library names based on the names used in the hook_libraries_info method.

$missing_message: The basic message to print before a listing of missing libraries and their download links.

Return value

bool True if a library was missing, false if no missing libraries.

1 call to _acquia_lift_missing_library_warning()
_acquia_lift_get_subreport in ./acquia_lift.admin.inc
Builds a limited report for a test directly from the test stats.

File

./acquia_lift.module, line 2284
acquia_lift.module Provides Acquia Lift-specific personalization functionality.

Code

function _acquia_lift_missing_library_warning($required_libraries, $missing_message) {
  $libraries = module_invoke('acquia_lift', 'libraries_info');
  $missing = array();
  foreach ($required_libraries as $required) {
    $detected = libraries_detect($required);
    if (empty($detected['installed'])) {
      $missing[] = array(
        'name' => $libraries[$required]['name'],
        'download_url' => $libraries[$required]['download url'],
      );
    }
    else {
      if (!empty($detected['error'])) {
        drupal_set_message($detected['error message'], 'error');
      }
    }
  }
  if (!empty($missing)) {
    $items = array();
    foreach ($missing as $lib) {
      $items[] = t('%libname - <a href="!download_url" target="_blank">download</a>', array(
        '%libname' => $lib['name'],
        '!download_url' => $lib['download_url'],
      ));
    }
    drupal_set_message(theme('item_list', array(
      'type' => 'ul',
      'title' => $missing_message,
      'items' => $items,
    )), 'error');
    return TRUE;
  }
  return FALSE;
}