You are here

function simple_fb_connect_requirements in Simple FB Connect 8.3

Same name and namespace in other branches
  1. 8.2 simple_fb_connect.install \simple_fb_connect_requirements()
  2. 7.2 simple_fb_connect.install \simple_fb_connect_requirements()
  3. 7 simple_fb_connect.install \simple_fb_connect_requirements()

Implements hook_requirements().

Checks that a compatible version of Facebook Graph SDK has been installed with Composer. Check installation instructions from the README.txt.

File

./simple_fb_connect.install, line 26
Install, update, and uninstall functions for the Simple FB Connect module.

Code

function simple_fb_connect_requirements($phase) {
  $requirements = [];
  if ($phase == 'install') {
    $sdk_found = FALSE;
    if ($json = simple_fb_connect_read_packages()) {

      // Loop through installed packages and check that the SDK version is OK.
      foreach ($json as $package) {
        if ($package['name'] == 'facebook/graph-sdk') {
          $sdk_found = TRUE;
          if ($package['version'] < 5 || $package['version'] >= 6) {
            $requirements['simple_fb_connect'] = [
              'description' => t('Simple FB Connect could not be installed because an incompatible version of Facebook SDK library was detected. Please read the installation instructions from README.txt.'),
              'severity' => REQUIREMENT_ERROR,
            ];
          }
        }
      }

      // SDK was not found in installed.json.
      if (!$sdk_found) {
        $requirements['simple_fb_connect'] = [
          'description' => t('Simple FB Connect could not be installed because Facebook SDK library was not found. Simple FB Connect must be installed using Composer. Please read the installation instructions from README.txt.'),
          'severity' => REQUIREMENT_ERROR,
        ];
      }
    }
    else {
      $requirements['simple_fb_connect'] = [
        'description' => t('Simple FB Connect could not be installed: installed.json could not be read.'),
        'severity' => REQUIREMENT_ERROR,
      ];
    }
  }
  return $requirements;
}