You are here

class FacebookAuth in Open Social 8.5

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

Defines a Network Plugin for Social Auth Facebook.

@package Drupal\social_auth_facebook\Plugin\Network

Plugin annotation


@Network(
  id = "social_auth_facebook",
  social_network = "Facebook",
  type = "social_auth",
  handlers = {
    "settings": {
      "class": "\Drupal\social_auth_facebook\Settings\FacebookAuthSettings",
      "config_id": "social_auth_facebook.settings"
    }
  }
)

Hierarchy

Expanded class hierarchy of FacebookAuth

File

modules/custom/social_auth_facebook/src/Plugin/Network/FacebookAuth.php, line 30

Namespace

Drupal\social_auth_facebook\Plugin\Network
View source
class FacebookAuth extends SocialAuthNetwork {
  protected $loggerFactory;

  /**
   * FacebookAuth 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 Facebook instance or FALSE if the config was incorrect.
   *
   * @throws \Drupal\social_api\SocialApiException
   */
  public function initSdk() {
    $class_name = '\\Facebook\\Facebook';
    if (!class_exists($class_name)) {
      throw new SocialApiException(sprintf('The PHP SDK for Facebook could not be found. Class: %s.', $class_name));
    }
    if (!$this
      ->validateConfig($this->settings)) {
      return FALSE;
    }
    $settings = [
      'app_id' => $this->settings
        ->getAppId(),
      'app_secret' => $this->settings
        ->getAppSecret(),
      'default_graph_version' => 'v' . $this->settings
        ->getGraphVersion(),
      'persistent_data_handler' => $this
        ->getDataHandler(),
    ];
    return new $class_name($settings);
  }

  /**
   * 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_facebook\Settings\FacebookAuthSettings $settings
   *   The Facebook auth settings.
   *
   * @return bool
   *   True if module is configured, False otherwise.
   */
  protected function validateConfig(FacebookAuthSettings $settings) {
    $app_id = $settings
      ->getAppId();
    $app_secret = $settings
      ->getAppSecret();
    $graph_version = $settings
      ->getGraphVersion();
    if (!$app_id || !$app_secret || !$graph_version) {
      $this->loggerFactory
        ->get('social_auth_facebook')
        ->error('Define App ID and App 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_facebook.persistent_data_handler');
    $data_handler
      ->setPrefix('social_auth_facebook_');
    return $data_handler;
  }

}

Members

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