abstract class NetworkBase in Social API 3.x
Same name and namespace in other branches
- 8.2 src/Plugin/NetworkBase.php \Drupal\social_api\Plugin\NetworkBase
- 8 src/Plugin/NetworkBase.php \Drupal\social_api\Plugin\NetworkBase
Base class for Social Network plugins.
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\social_api\Plugin\NetworkBase implements NetworkInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of NetworkBase
File
- src/
Plugin/ NetworkBase.php, line 17
Namespace
Drupal\social_api\PluginView source
abstract class NetworkBase extends PluginBase implements NetworkInterface {
/**
* The logger factory.
*
* @var \Drupal\Core\Logger\LoggerChannelFactoryInterface
*/
protected $loggerFactory;
/**
* The global site settings.
*
* @var \Drupal\Core\Site\Settings
*/
protected $siteSettings;
/**
* The implementer/plugin settings.
*
* @var \Drupal\social_api\Settings\SettingsInterface
*/
protected $settings;
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* The SDK client.
*
* @var mixed
*/
protected $sdk;
/**
* Sets the underlying SDK library.
*
* @return mixed
* The initialized 3rd party library instance.
*
* @throws \Drupal\social_api\SocialApiException
* If the SDK library does not exist.
*/
protected abstract function initSdk();
/**
* Instantiates a NetworkBase object.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param array $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Logger\LoggerChannelFactoryInterface $logger_factory
* The logger factory.
* @param \Drupal\Core\Site\Settings $settings
* The site settings.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The configuration factory object.
*/
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);
}
/**
* Initialize the plugin.
*
* This method is called upon plugin instantiation. Instantiates the settings
* wrapper.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The injected configuration factory.
*
* @throws \Drupal\social_api\SocialApiException
* When the settings are not valid.
*/
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;
}
}
/**
* {@inheritdoc}
*/
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'));
}
/**
* {@inheritdoc}
*/
public function getSdk() {
if (!$this->sdk) {
$this->sdk = $this
->initSdk();
}
return $this->sdk;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
public | function | 2 | |
DependencySerializationTrait:: |
public | function | 2 | |
MessengerTrait:: |
protected | property | The messenger. | 27 |
MessengerTrait:: |
public | function | Gets the messenger. | 27 |
MessengerTrait:: |
public | function | Sets the messenger. | |
NetworkBase:: |
protected | property | The entity type manager. | |
NetworkBase:: |
protected | property | The logger factory. | |
NetworkBase:: |
protected | property | The SDK client. | |
NetworkBase:: |
protected | property | The implementer/plugin settings. | |
NetworkBase:: |
protected | property | The global site settings. | |
NetworkBase:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
|
NetworkBase:: |
public | function |
Gets the underlying SDK library. Overrides NetworkInterface:: |
|
NetworkBase:: |
protected | function | Initialize the plugin. | |
NetworkBase:: |
abstract protected | function | Sets the underlying SDK library. | |
NetworkBase:: |
public | function |
Instantiates a NetworkBase object. Overrides PluginBase:: |
|
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
2 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 4 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |