You are here

function simple_fb_connect_read_packages in Simple FB Connect 8.3

Reads and parses Drupal installed.json.

Return value

array|bool Parsed installed.json if the file could be read and parsed. False otherwise.

See also

https://www.drupal.org/node/2873333

1 call to simple_fb_connect_read_packages()
simple_fb_connect_requirements in ./simple_fb_connect.install
Implements hook_requirements().

File

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

Code

function simple_fb_connect_read_packages() {

  // Drupal can be installed with Composer or traditionally from a tarball.
  // - If installed from a tarball or with Composer using drupal/drupal,
  //   DRUPAL_ROOT is the acutal website filesystem root.
  // - If installed with Composer using drupal-composer/drupal-project,
  //   DRUPAL_ROOT is a 'web' sub directory of the Composer project directory.
  $base_dir = is_dir(DRUPAL_ROOT . '/vendor') ? DRUPAL_ROOT : dirname(DRUPAL_ROOT);
  $file_path = $base_dir . '/vendor/composer/installed.json';
  if (file_exists($file_path)) {
    if ($filedata = @file_get_contents($file_path)) {
      $json = @json_decode($filedata, TRUE);
      if ($json !== NULL) {
        return $json;
      }
    }
  }
  return FALSE;
}