You are here

class TwitterAuth in Open Social 8.5

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

Defines Social Auth Twitter Network Plugin.

Plugin annotation


@Network(
  id = "social_auth_twitter",
  social_network = "Twitter",
  type = "social_auth",
  handlers = {
    "settings": {
       "class": "\Drupal\social_auth_twitter\Settings\TwitterAuthSettings",
       "config_id": "social_auth_twitter.settings"
    }
  }
)

Hierarchy

Expanded class hierarchy of TwitterAuth

File

modules/custom/social_auth_twitter/src/Plugin/Network/TwitterAuth.php, line 28

Namespace

Drupal\social_auth_twitter\Plugin\Network
View source
class TwitterAuth extends SocialAuthNetwork {
  protected $loggerFactory;

  /**
   * TwitterAuth 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'));
  }

  /**
   * {@inheritdoc}
   */
  public function initSdk() {
    $class_name = '\\Abraham\\TwitterOAuth\\TwitterOAuth';
    if (!class_exists($class_name)) {
      throw new SocialApiException(sprintf('The PHP SDK for Twitter Client could not be found. Class: %s.', $class_name));
    }

    /* @var \Drupal\social_auth_twitter\Settings\TwitterAuthSettings $settings */
    $settings = $this->settings;
    if (!$this
      ->validateConfig($settings)) {
      return FALSE;
    }

    // Creates a and sets data to TwitterOAuth object.
    return new $class_name($settings
      ->getConsumerKey(), $settings
      ->getConsumerSecret());
  }

  /**
   * 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_twitter\Settings\TwitterAuthSettings $settings
   *   The Twitter auth settings.
   *
   * @return bool
   *   True if module is configured, False otherwise.
   */
  protected function validateConfig(TwitterAuthSettings $settings) {
    $consumer_key = $settings
      ->getConsumerKey();
    $consumer_secret = $settings
      ->getConsumerSecret();
    if (!$consumer_key || !$consumer_secret) {
      $this->loggerFactory
        ->get('social_auth_twitter')
        ->error('Define Consumer Key and Consumer 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_twitter_');
    return $data_handler;
  }

}

Members

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