You are here

class LinkedInAuth in Open Social 8.3

Same name and namespace in other branches
  1. 8.9 modules/custom/social_auth_linkedin/src/Plugin/Network/LinkedInAuth.php \Drupal\social_auth_linkedin\Plugin\Network\LinkedInAuth
  2. 8 modules/custom/social_auth_linkedin/src/Plugin/Network/LinkedInAuth.php \Drupal\social_auth_linkedin\Plugin\Network\LinkedInAuth
  3. 8.2 modules/custom/social_auth_linkedin/src/Plugin/Network/LinkedInAuth.php \Drupal\social_auth_linkedin\Plugin\Network\LinkedInAuth
  4. 8.4 modules/custom/social_auth_linkedin/src/Plugin/Network/LinkedInAuth.php \Drupal\social_auth_linkedin\Plugin\Network\LinkedInAuth
  5. 8.5 modules/custom/social_auth_linkedin/src/Plugin/Network/LinkedInAuth.php \Drupal\social_auth_linkedin\Plugin\Network\LinkedInAuth
  6. 8.6 modules/custom/social_auth_linkedin/src/Plugin/Network/LinkedInAuth.php \Drupal\social_auth_linkedin\Plugin\Network\LinkedInAuth
  7. 8.7 modules/custom/social_auth_linkedin/src/Plugin/Network/LinkedInAuth.php \Drupal\social_auth_linkedin\Plugin\Network\LinkedInAuth
  8. 8.8 modules/custom/social_auth_linkedin/src/Plugin/Network/LinkedInAuth.php \Drupal\social_auth_linkedin\Plugin\Network\LinkedInAuth

Defines a Network Plugin for Social Auth LinkedIn.

@package Drupal\social_auth_linkedin\Plugin\Network

Plugin annotation


@Network(
  id = "social_auth_linkedin",
  social_network = "LinkedIn",
  type = "social_auth",
  handlers = {
    "settings": {
      "class": "\Drupal\social_auth_linkedin\Settings\LinkedInAuthSettings",
      "config_id": "social_auth_linkedin.settings"
    }
  }
)

Hierarchy

Expanded class hierarchy of LinkedInAuth

File

modules/custom/social_auth_linkedin/src/Plugin/Network/LinkedInAuth.php, line 30

Namespace

Drupal\social_auth_linkedin\Plugin\Network
View source
class LinkedInAuth extends SocialAuthNetwork {
  protected $loggerFactory;

  /**
   * LinkedInAuth constructor.
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, ConfigFactoryInterface $config_factory, LoggerChannelFactoryInterface $logger_factory) {
    $this->loggerFactory = $logger_factory;
    parent::__construct($configuration, $plugin_id, $plugin_definition, $entity_type_manager, $config_factory);
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    return new static($configuration, $plugin_id, $plugin_definition, $container
      ->get('entity_type.manager'), $container
      ->get('config.factory'), $container
      ->get('logger.factory'));
  }

  /**
   * Returns an instance of sdk.
   *
   * @return mixed
   *   Returns a new LinkedIn instance or FALSE if the config was incorrect.
   *
   * @throws \Drupal\social_api\SocialApiException
   */
  public function initSdk() {
    $class_name = '\\Happyr\\LinkedIn\\LinkedIn';
    if (!class_exists($class_name)) {
      throw new SocialApiException(sprintf('The PHP SDK for LinkedIn could not be found. Class: %s.', $class_name));
    }
    if (!$this
      ->validateConfig($this->settings)) {
      return FALSE;
    }
    return new $class_name($this->settings
      ->getClientId(), $this->settings
      ->getClientSecret());
  }

  /**
   * Returns status of social network.
   *
   * @return bool
   *   The status of the social network.
   */
  public function isActive() {
    return (bool) $this->settings
      ->isActive();
  }

  /**
   * Checks that module is configured.
   *
   * @param \Drupal\social_auth_linkedin\Settings\LinkedInAuthSettings $settings
   *   The LinkedIn auth settings.
   *
   * @return bool
   *   True if module is configured, False otherwise.
   */
  protected function validateConfig(LinkedInAuthSettings $settings) {
    $client_id = $settings
      ->getClientId();
    $client_secret = $settings
      ->getClientSecret();
    if (!$client_id || !$client_secret) {
      $this->loggerFactory
        ->get('social_auth_linkedin')
        ->error('Define Client ID and Client Secret on module settings.');
      return FALSE;
    }
    return TRUE;
  }

  /**
   * {@inheritdoc}
   */
  public function getSocialNetworkKey() {
    return $this->settings
      ->getSocialNetworkKey();
  }

  /**
   * Returns an instance of storage that handles data.
   *
   * @return object
   *   An instance of the storage that handles the data.
   */
  public function getDataHandler() {
    $data_handler = \Drupal::service('social_auth_extra.session_persistent_data_handler');
    $data_handler
      ->setPrefix('social_auth_linkedin_');
    return $data_handler;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
LinkedInAuth::$loggerFactory protected property
LinkedInAuth::create public static function
LinkedInAuth::getDataHandler public function Returns an instance of storage that handles data.
LinkedInAuth::getSocialNetworkKey public function
LinkedInAuth::initSdk public function Returns an instance of sdk.
LinkedInAuth::isActive public function Returns status of social network.
LinkedInAuth::validateConfig protected function Checks that module is configured.
LinkedInAuth::__construct public function LinkedInAuth constructor.