You are here

function bynder_requirements in Bynder 8.2

Same name and namespace in other branches
  1. 8.3 bynder.install \bynder_requirements()
  2. 8 bynder.install \bynder_requirements()
  3. 4.0.x bynder.install \bynder_requirements()

Implements hook_requirements().

File

./bynder.install, line 17
Install, uninstall and update hooks for Bynder module.

Code

function bynder_requirements($phase) {
  $requirements = [];
  $imagesloaded_path = DRUPAL_ROOT . '/libraries/imagesloaded/imagesloaded.pkgd.min.js';
  $masonry_path = DRUPAL_ROOT . '/libraries/masonry/dist/masonry.pkgd.min.js';
  if (!file_exists($imagesloaded_path)) {
    $requirements['imagesloaded'] = [
      'title' => t('ImagesLoaded library missing'),
      'description' => t('Bynder requires the imagesLoaded library. Download the newest release from https://github.com/desandro/imagesloaded releases and place it in /libraries'),
      'severity' => REQUIREMENT_ERROR,
    ];
  }
  if (!file_exists($masonry_path)) {
    $requirements['masonry'] = [
      'title' => t('Masonry library missing'),
      'description' => t('Bynder requires the Masonry library. Download the newest release from https://github.com/desandro/masonry/releases and place it in /libraries'),
      'severity' => REQUIREMENT_ERROR,
    ];
  }

  // Test if we can connect to the Bynder API.
  if ($phase === 'runtime') {
    $api = \Drupal::service('bynder_api');
    try {
      $api
        ->getBrands();
      $requirements['bynder'] = [
        'title' => t('Bynder'),
        'value' => t('Connected to @url', [
          '@url' => \Drupal::config('bynder.settings')
            ->get('account_domain'),
        ]),
      ];
    } catch (\Exception $e) {
      $requirements['bynder'] = [
        'title' => t('Bynder'),
        'value' => t('Error connecting to @url', [
          '@url' => \Drupal::config('bynder.settings')
            ->get('account_domain'),
        ]),
        'description' => $e
          ->getMessage(),
        'severity' => REQUIREMENT_ERROR,
      ];
    }
  }
  return $requirements;
}