You are here

class Facebook in Social simple 8

Same name and namespace in other branches
  1. 2.0.x src/SocialNetwork/Facebook.php \Drupal\social_simple\SocialNetwork\Facebook

The social network Facebook.

Hierarchy

Expanded class hierarchy of Facebook

2 string references to 'Facebook'
Facebook::getLabel in src/SocialNetwork/Facebook.php
Get the network name.
social_simple.services.yml in ./social_simple.services.yml
social_simple.services.yml
1 service uses Facebook
social_simple.facebook in ./social_simple.services.yml
Drupal\social_simple\SocialNetwork\Facebook

File

src/SocialNetwork/Facebook.php, line 12

Namespace

Drupal\social_simple\SocialNetwork
View source
class Facebook implements SocialNetworkInterface {
  use StringTranslationTrait;

  /**
   * The social network base share link.
   */
  const FACEBOOK_URL = 'https://www.facebook.com/sharer/sharer.php';

  /**
   * {@inheritdoc}
   */
  public function getId() {
    return 'facebook';
  }

  /**
   * {@inheritdoc}
   */
  public function getLabel() {
    return $this
      ->t('Facebook');
  }

  /**
   * {@inheritdoc}
   */
  public function getShareLink($share_url, $title = '', EntityInterface $entity = NULL, array $additional_options = []) {
    $options = [
      'query' => [
        'u' => $share_url,
      ],
      'absolute' => TRUE,
      'external' => TRUE,
    ];
    if ($additional_options) {
      foreach ($additional_options as $id => $value) {
        $options['query'][$id] = $value;
      }
    }
    $url = Url::fromUri(self::FACEBOOK_URL, $options);
    $link = [
      'url' => $url,
      'title' => [
        '#markup' => '<i class="fa fa-facebook"></i><span class="visually-hidden">' . $this
          ->getLabel() . '</span>',
      ],
      'attributes' => $this
        ->getLinkAttributes($this
        ->getLabel()),
    ];
    return $link;
  }

  /**
   * {@inheritdoc}
   */
  public function getLinkAttributes($network_name) {
    $attributes = [
      'data-popup-width' => 600,
      'data-popup-height' => 300,
      'data-toggle' => 'tooltip',
      'data-placement' => 'top',
      'title' => $network_name,
    ];
    return $attributes;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Facebook::FACEBOOK_URL constant The social network base share link.
Facebook::getId public function Get the network id. Overrides SocialNetworkInterface::getId
Facebook::getLabel public function Get the network name. Overrides SocialNetworkInterface::getLabel
Facebook::getLinkAttributes public function Get common attributes for the share link. Overrides SocialNetworkInterface::getLinkAttributes
Facebook::getShareLink public function Checks whether the given transition is allowed. Overrides SocialNetworkInterface::getShareLink
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.