Mail.php in Social simple 8
File
src/SocialNetwork/Mail.php
View source
<?php
namespace Drupal\social_simple\SocialNetwork;
use Drupal\Core\Config\Entity\ConfigEntityInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\Url;
class Mail implements SocialNetworkInterface {
use StringTranslationTrait;
const MAIL = 'mailto:';
protected $moduleHandler;
public function __construct(ModuleHandlerInterface $moduleHandler) {
$this->moduleHandler = $moduleHandler;
}
public function getId() {
return 'mail';
}
public function getLabel() {
return $this
->t('Mail');
}
public function getShareLink($share_url, $title = '', EntityInterface $entity = NULL, array $additional_options = []) {
$options = [
'query' => [
'body' => PHP_EOL . $title . PHP_EOL . $share_url,
'subject' => $title,
],
'absolute' => TRUE,
'external' => TRUE,
];
if ($additional_options) {
foreach ($additional_options as $id => $value) {
$options['query'][$id] = $value;
}
}
if ($entity && $this
->checkForwardIntegration($entity)) {
$url = Url::fromRoute('forward.form', [
'entity_type' => $entity
->getEntityTypeId(),
'entity' => $entity
->id(),
]);
}
else {
$url = Url::fromUri(self::MAIL, $options);
}
$link = [
'url' => $url,
'title' => [
'#markup' => '<i class="fa fa-envelope"></i><span class="visually-hidden">' . $this
->getLabel() . '</span>',
],
'attributes' => $this
->getLinkAttributes($this
->getLabel()),
];
return $link;
}
public function getLinkAttributes($network_name) {
$attributes = [
'title' => $network_name,
'data-popup-open' => 'false',
];
return $attributes;
}
protected function checkForwardIntegration(EntityInterface $entity) {
if (!$this->moduleHandler
->moduleExists('forward')) {
return FALSE;
}
$entity_type = $entity->type->entity;
if (!$entity_type instanceof ConfigEntityInterface) {
return FALSE;
}
return $entity_type
->getThirdPartySetting('social_simple', 'forward_integration', FALSE);
}
}