You are here

abstract class NetworkBase in Social API 8

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

Base class for Social Network plugins.

Hierarchy

Expanded class hierarchy of NetworkBase

File

src/Plugin/NetworkBase.php, line 15

Namespace

Drupal\social_api\Plugin
View source
abstract class NetworkBase extends PluginBase implements NetworkInterface {

  /**
   * Stores the settings wrapper object.
   *
   * @var SettingsInterface
   */
  protected $settings;

  /**
   * The entity type manager.
   *
   * @var EntityTypeManagerInterface
   */
  protected $entityTypeManager;

  /**
   * Sets the underlying SDK library.
   *
   * @return mixed $library_instance
   *   The initialized 3rd party library instance.
   *
   * @throws 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 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, EntityTypeManagerInterface $entity_type_manager, ConfigFactoryInterface $config_factory) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $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 ConfigFactoryInterface $config_factory
   *   The injected configuration factory.
   *
   * @throws 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) {

    /* @var EntityTypeManagerInterface $entity_type_manager */
    $entity_type_manager = $container
      ->get('entity_type.manager');

    /* @var ConfigFactoryInterface $config_factory */
    $config_factory = $container
      ->get('config.factory');
    return new static($configuration, $plugin_id, $plugin_definition, $entity_type_manager, $config_factory);
  }

  /**
   * {@inheritdoc}
   *
   * By default assume that no action needs to happen to authenticate a request.
   */
  public function authenticate() {

    // Do nothing by default.
  }

  /**
   * {@inheritdoc}
   */
  public function getSdk() {
    if (empty($this->sdk)) {
      $this->sdk = $this
        ->initSdk();
    }
    return $this->sdk;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
NetworkBase::$entityTypeManager protected property The entity type manager.
NetworkBase::$settings protected property Stores the settings wrapper object.
NetworkBase::authenticate public function By default assume that no action needs to happen to authenticate a request. Overrides NetworkInterface::authenticate
NetworkBase::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create
NetworkBase::getSdk public function Gets the underlying SDK library. Overrides NetworkInterface::getSdk
NetworkBase::init protected function Initialize the plugin.
NetworkBase::initSdk abstract protected function Sets the underlying SDK library.
NetworkBase::__construct public function Instantiates a NetworkBase object. Overrides PluginBase::__construct
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.