You are here

function commerce_square_requirements in Commerce Square Connect 7

Same name and namespace in other branches
  1. 8 commerce_square.install \commerce_square_requirements()

Implements hook_requirements().

File

./commerce_square.install, line 11
Commerce Square install file.

Code

function commerce_square_requirements($phase) {
  $requirements = array();
  if ($phase == 'runtime') {
    $t = get_t();
    $library = libraries_detect('square');
    if ($library['installed'] === TRUE) {
      $requirements['commerce_square'] = array(
        'title' => $t('Square Connect SDK'),
        'value' => $t('Installed: @version', array(
          '@version' => $library['version'],
        )),
        'severity' => REQUIREMENT_OK,
      );

      // Compare installed version.
      list($major, $minor, $patch) = explode('.', $library['version']);
      if ($major != 2) {
        $requirements['commerce_square']['severity'] = REQUIREMENT_ERROR;
        $requirements['commerce_square']['description'] = $t('The Square Connect SDK v2.x.x is only supported. Currently @version is discovered', array(
          '@version' => $library['version'],
        ));
      }
    }
    else {
      $requirements['commerce_square'] = array(
        'title' => $t('Square Connect SDK'),
        'value' => $t('Missing'),
        'severity' => REQUIREMENT_ERROR,
        'description' => $t('Square Connect SDK library missing. Download the library from <a href="!url">!url</a> and place it in to sites/all/libraries/square', array(
          '!url' => $library['download url'],
        )),
      );
    }
  }
  return $requirements;
}