You are here

function _acquia_lift_missing_library_warning in Acquia Lift Connector 7

Same name and namespace in other branches
  1. 7.2 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.

2 calls to _acquia_lift_missing_library_warning()
acquia_lift_report_ab in ./acquia_lift.admin.inc
Form build function for an A/B Acquia Lift agent report.
acquia_lift_report_custom in ./acquia_lift.admin.inc
Form build function for a custom Acquia Lift agent report.

File

./acquia_lift.module, line 2116
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;
}