You are here

public function SocialSimpleGenerator::buildSocialLinks in Social simple 2.0.x

Same name and namespace in other branches
  1. 8 src/SocialSimpleGenerator.php \Drupal\social_simple\SocialSimpleGenerator::buildSocialLinks()

Build the render array of social share links.

Parameters

array $networks: An array of social network name keyed with network id.

string $title: The title to use for the share links.

\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::buildSocialLinks

File

src/SocialSimpleGenerator.php, line 102

Class

SocialSimpleGenerator
Class SocialSimpleGenerator.

Namespace

Drupal\social_simple

Code

public function buildSocialLinks(array $networks, $title, EntityInterface $entity = NULL, array $options = []) {
  $links = $this
    ->generateSocialLinks($networks, $entity, $options);
  $build = [
    '#theme' => 'social_simple_buttons',
    '#links' => $links,
    '#attributes' => [
      'class' => [
        'links',
        'inline',
        'social-buttons-links',
      ],
    ],
    '#heading' => [
      'text' => $title,
      'level' => 'div',
      'attributes' => [
        'class' => [
          'social-buttons-title',
        ],
      ],
    ],
  ];
  $build['#attached']['library'][] = 'social_simple/buttons';
  return $build;
}