You are here

function bynder_requirements in Bynder 8.3

Same name and namespace in other branches
  1. 8 bynder.install \bynder_requirements()
  2. 8.2 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 = [];

  // 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;
}