public function SocialSimpleGenerator::generateSocialLinks in Social simple 8
Same name and namespace in other branches
- 2.0.x src/SocialSimpleGenerator.php \Drupal\social_simple\SocialSimpleGenerator::generateSocialLinks()
Build the social share links.
Parameters
array $networks: An array of social network name keyed with network id.
\Drupal\Core\Entity\EntityInterface $entity: The entity if provided.
array $options: Additional options to pass as a query for the url built. The array must be keyed by network_id. Example. $options = [ 'twitter' => [ 'hastags' => 'hashtag1, hashtag2', ], ];.
Return value
array $links An array of social share links.
Overrides SocialSimpleGeneratorInterface::generateSocialLinks
1 call to SocialSimpleGenerator::generateSocialLinks()
- SocialSimpleGenerator::buildSocialLinks in src/
SocialSimpleGenerator.php - Build the render array of social share links.
File
- src/
SocialSimpleGenerator.php, line 127
Class
- SocialSimpleGenerator
- Class SocialSimpleGenerator.
Namespace
Drupal\social_simpleCode
public function generateSocialLinks(array $networks, EntityInterface $entity = NULL, array $options = []) {
$links = [];
$title = $this
->getTitle($entity);
$share_url = $this
->getShareUrl($entity);
$networks_supported = $this
->getNetworks();
$networks = array_intersect_key($networks_supported, $networks);
foreach ($networks as $network_id => $network_name) {
$additional_options = isset($options[$network_id]) ? $options[$network_id] : [];
if ($this->socialSimpleManager
->get($network_id) instanceof SocialNetworkInterface) {
$links[$network_id] = $this->socialSimpleManager
->get($network_id)
->getShareLink($share_url, $title, $entity, $additional_options);
}
}
return $links;
}