You are here

function tweetbutton_tweet_get_attributes in Tweet Button 8

Same name and namespace in other branches
  1. 7.2 tweetbutton.module \tweetbutton_tweet_get_attributes()

Helper function to build the required tweet attributes.

Parameters

array $options: Context specific options.

Return value

List of attributes to be rendered for tweet button.

1 call to tweetbutton_tweet_get_attributes()
theme_tweetbutton_tweet_display in ./tweetbutton.module
Returns HTML for a tweet button.

File

./tweetbutton.module, line 90
Adds block with tweet and follow buttons.

Code

function tweetbutton_tweet_get_attributes($options = array()) {
  $config = \Drupal::config('tweetbutton.settings');
  $default_option = array(
    'account' => $config
      ->get('tweetbutton_account'),
    'text' => $config
      ->get('tweetbutton_tweet_text'),
    'rel_account' => $config
      ->get('tweetbutton_rel_account_name'),
    'rel_description' => $config
      ->get('tweetbutton_rel_account_description'),
    'language' => $config
      ->get('tweetbutton_language'),
    'hashtags' => $config
      ->get('tweetbutton_hashtags'),
  );

  // @TODO: Integration with module shorten.
  $default_option['url'] = '';
  $default_option['count_url'] = '';
  $options += $default_option;
  $attributes = array(
    'data-url' => $options['url'],
    'data-via' => $options['account'],
    'data-text' => $options['text'],
    'data-related' => $options['rel_account'] . ':' . $options['rel_description'],
    'data-count' => $options['count'],
    'data-lang' => $options['language'],
    'data-counturl' => $options['count_url'],
    'data-hashtags' => $options['hashtags'],
    'data-size' => $options['size'],
    'data-dnt' => $options['dnt'] ? 'true' : 'false',
    'class' => 'twitter-share-button',
  );
  return $attributes;
}