Facebook.php in Social simple 8
File
src/SocialNetwork/Facebook.php
View source
<?php
namespace Drupal\social_simple\SocialNetwork;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Url;
class Facebook implements SocialNetworkInterface {
use StringTranslationTrait;
const FACEBOOK_URL = 'https://www.facebook.com/sharer/sharer.php';
public function getId() {
return 'facebook';
}
public function getLabel() {
return $this
->t('Facebook');
}
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;
}
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;
}
}