You are here

protected function NetworkBase::init in Social API 8

Same name and namespace in other branches
  1. 8.2 src/Plugin/NetworkBase.php \Drupal\social_api\Plugin\NetworkBase::init()
  2. 3.x src/Plugin/NetworkBase.php \Drupal\social_api\Plugin\NetworkBase::init()

Initialize the plugin.

This method is called upon plugin instantiation. Instantiates the settings wrapper.

Parameters

ConfigFactoryInterface $config_factory: The injected configuration factory.

Throws

SocialApiException When the settings are not valid.

1 call to NetworkBase::init()
NetworkBase::__construct in src/Plugin/NetworkBase.php
Instantiates a NetworkBase object.

File

src/Plugin/NetworkBase.php, line 75

Class

NetworkBase
Base class for Social Network plugins.

Namespace

Drupal\social_api\Plugin

Code

protected function init(ConfigFactoryInterface $config_factory) {
  $definition = $this
    ->getPluginDefinition();
  if (!empty($definition['handlers']['settings']['class']) && !empty($definition['handlers']['settings']['config_id'])) {
    if (!class_exists($definition['handlers']['settings']['class'])) {
      throw new SocialApiException('The specified settings class does not exist. Please check your plugin annotation.');
    }
    $config = $config_factory
      ->get($definition['handlers']['settings']['config_id']);
    $settings = call_user_func($definition['handlers']['settings']['class'] . '::factory', $config);
    if (!$settings instanceof SettingsInterface) {
      throw new SocialApiException('The provided settings class does not implement the expected settings interface.');
    }
    $this->settings = $settings;
  }
}