You are here

function easy_social_preprocess_easy_social_twitter in Easy Social 8.4

Same name and namespace in other branches
  1. 8.3 easy_social.module \easy_social_preprocess_easy_social_twitter()

Implements hook_preprocess_HOOK() for easy_social_facebook theme.

See also

easy_social_theme()

theme_easy_social_facebook()

File

./easy_social.module, line 181
Easy Social module.

Code

function easy_social_preprocess_easy_social_twitter(&$variables, $hook) {

  // Incidentally, the hook name is almost what we expect the config name to be.
  $hook = str_replace('easy_social_', 'easy_social.', $hook);
  $attributes = array(
    'class' => array(
      'twitter-share-button',
    ),
  );
  if ($config = \Drupal::config($hook)) {

    // @TODO load contextual config.
    $widget_params = $config
      ->get();
    if (!empty($widget_params['via'])) {
      $attributes['data-via'] = $widget_params['via'];
    }
    if (!empty($widget_params['related'])) {
      $attributes['data-related'] = $widget_params['related'];
    }
    if (isset($widget_params['size'])) {
      $attributes['data-size'] = $widget_params['size'] == 1 ? 'large' : 'medium';
    }
    if (!empty($widget_params['count'])) {
      $attributes['data-count'] = $widget_params['count'];
    }
    if (!empty($widget_params['lang'])) {
      $attributes['data-lang'] = $widget_params['lang'];
    }
    if (!empty($widget_params['hashtags'])) {
      $attributes['data-hashtags'] = $widget_params['hashtags'];
    }
    if (isset($widget_params['dnt']) && $widget_params['dnt'] == 1) {
      $attributes['data-dnt'] = 'true';
    }
  }
  $variables['attributes'] = $attributes;
}