You are here

public static function DrupalClientFactory::create in Facebook Instant Articles 8.2

Same name and namespace in other branches
  1. 3.x src/DrupalClientFactory.php \Drupal\fb_instant_articles\DrupalClientFactory::create()

Create an instance of DrupalClient.

Parameters

\Drupal\Core\Config\ConfigFactoryInterface $config_factory: Config factory service.

Return value

\Drupal\fb_instant_articles\DrupalClient Instance of DrupalClient.

Throws

\Drupal\fb_instant_articles\MissingApiCredentialsException

File

src/DrupalClientFactory.php, line 23

Class

DrupalClientFactory
Factory class to create a \Drupal\fb_instant_articles\DrupalClient.

Namespace

Drupal\fb_instant_articles

Code

public static function create(ConfigFactoryInterface $config_factory) {
  $config = $config_factory
    ->get('fb_instant_articles.settings');
  $app_id = $config
    ->get('app_id');
  $app_secret = $config
    ->get('app_secret');
  $access_token = $config
    ->get('access_token');
  if (empty($app_id) || empty($app_secret) || empty($access_token)) {
    throw new MissingApiCredentialsException('The Facebook Instant Articles API has not been configured yet.');
  }
  $client = DrupalClient::create($config
    ->get('app_id'), $config
    ->get('app_secret'), $config
    ->get('access_token'), $config
    ->get('page_id'), $config
    ->get('development_mode') ? TRUE : FALSE);
  return $client;
}