This widget adds share links for social networks.
It supports from the box
- VK
- Google+
- Telegram
- Viber
- Gmail
composer require black-lamp/yii2-socialshare
or add
"black-lamp/yii2-socialshare": "1.*.*"
to the require section of your composer.json.
'components' => [
// ...
'socialShare' => [
'class' => bl\socialShare\SocialShare::className(),
'defaultIcons' => true,
'attributes' => [
'class' => 'social-btn'
],
'networks' => [
'facebook' => [
'class' => bl\socialShare\classes\Facebook::className(),
'label' => 'Facebook'
],
'twitter' => [
'class' => bl\socialShare\classes\Twitter::className(),
'label' => 'Twitter',
// custom option for Twitter class
'account' => 'twitterAccount'
],
'googlePlus' => [
'class' => bl\socialShare\classes\GooglePlus::className(),
'label' => 'Google+'
],
'vk' => [
'class' => bl\socialShare\classes\Vkontakte::className(),
'label' => 'vk'
],
// other social networks ...
]
],
]
In this component you need to add and configure social network classes
Option | Description | Type | Default |
---|---|---|---|
networks | Array of social networks classes configuration | array | - |
attributes | HTML attributes for all share links | array | - |
defaultIcons | Use default font-icons instead text labels or not | boolean | false |
enableSeo | Enable or disable appending SEO attributes from seoAttributes array for links |
boolean | true |
seoAttributes | Array of SEO attributes for links | array | ['target' => '_blank', 'rel' => 'nofollow'] |
Option | Description | Type |
---|---|---|
class | Namespace of social network class | string |
label | Text for link | string |
attributes | HTML attributes for share link | array |
You should use the widget for adding the share links on page
<?= \bl\socialShare\widgets\SocialShareWidget::widget([
'componentId' => 'socialShare',
'url' => Url::toRoute(['site/index'], true),
'title' => 'Black Lamp - digital agancy',
'description' => 'Black Lamp provides a comprehensive range of services for development...',
'image' => Url::toRoute(['/logo.png'], true)
]) ?>
Option | Description | Type |
---|---|---|
componentId | id of SocialShare component from config | string |
url | Absolute URL to the page | string |
title | Page title | string |
description | Page description | string |
image | Absolute URL to the image for page | string |
exceptions | Exceptions for social networks. In this array you can override default title, description, link or image. | array |
You must create class and extend it from bl\socialShare\base\SocialNetwork abstract class
use bl\socialShare\base\SocialNetwork;
class LinkedIn extends SocialNetwork
{
}
and implement the method getLink()
class LinkedIn extends bl\socialShare\base\SocialNetwork
{
/**
* @inheritdoc
*/
public function getLink($url, $title, $description, $image, $component)
{
}
}
this method must initialize route to the social network
and return initLink()
method with $component
argument
/**
* @inheritdoc
*/
public function getLink($url, $title, $description, $image, $component)
{
$this->_route = "https://www.linkedin.com/shareArticle?mini=true"
."&url=$url"
."&title=$title"
."&summary=$description";
return $this->initLink($component);
}
yii2-social-networks - this widget adds links to social networks