NetworkBase.php in Social API 8.2
File
src/Plugin/NetworkBase.php
View source
<?php
namespace Drupal\social_api\Plugin;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Logger\LoggerChannelFactoryInterface;
use Drupal\Core\Plugin\PluginBase;
use Drupal\Core\Site\Settings;
use Drupal\social_api\Settings\SettingsInterface;
use Drupal\social_api\SocialApiException;
use Symfony\Component\DependencyInjection\ContainerInterface;
abstract class NetworkBase extends PluginBase implements NetworkInterface {
protected $loggerFactory;
protected $siteSettings;
protected $settings;
protected $entityTypeManager;
protected $sdk;
protected abstract function initSdk();
public function __construct(array $configuration, $plugin_id, array $plugin_definition, LoggerChannelFactoryInterface $logger_factory, Settings $settings, EntityTypeManagerInterface $entity_type_manager, ConfigFactoryInterface $config_factory) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->loggerFactory = $logger_factory;
$this->siteSettings = $settings;
$this->entityTypeManager = $entity_type_manager;
$this->configuration = $entity_type_manager;
$this
->init($config_factory);
}
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;
}
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('logger.factory'), $container
->get('settings'), $container
->get('entity_type.manager'), $container
->get('config.factory'));
}
public function getSdk() {
if (!$this->sdk) {
$this->sdk = $this
->initSdk();
}
return $this->sdk;
}
}