You are here

function easy_social_preprocess_easy_social_facebook in Easy Social 8.3

Same name and namespace in other branches
  1. 8.4 easy_social.module \easy_social_preprocess_easy_social_facebook()

Implements hook_preprocess_HOOK() for easy_social_facebook theme.

See also

easy_social_theme()

theme_easy_social_facebook()

File

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

Code

function easy_social_preprocess_easy_social_facebook(&$variables, &$hook) {

  // @TODO implement this.
  $lang = 'en_US';

  // 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(
      'fb-like',
    ),
  );
  if ($config = \Drupal::config($hook)) {

    // @TODO load contextual config.
    $widget_params = $config
      ->get();
    if (!empty($variables['url'])) {
      $attributes['data-href'] = $variables['url'];
    }
    if (isset($widget_params['send']) && $widget_params['send'] == 1) {
      $attributes['data-send'] = 'true';
    }
    if (isset($widget_params['share']) && $widget_params['share'] == 1) {
      $attributes['data-share'] = 'true';
    }
    if (isset($widget_params['show_faces']) && $widget_params['show_faces'] == 1) {
      $attributes['data-show-faces'] = 'true';
    }
    if (!empty($widget_params['width'])) {
      $attributes['data-width'] = $widget_params['width'];
    }
    if (isset($widget_params['layout']) && $widget_params['layout'] !== 'standard') {
      $attributes['data-layout'] = $widget_params['layout'];
    }
    if (!empty($widget_params['font'])) {
      $attributes['data-font'] = $widget_params['font'];
    }
    if (isset($widget_params['colorscheme']) && $widget_params['colorscheme'] !== 'light') {
      $attributes['data-colorscheme'] = $widget_params['colorscheme'];
    }
    if (isset($widget_params['action']) && $widget_params['action'] !== 'like') {
      $attributes['data-action'] = $widget_params['action'];
    }
  }
  $variables['attributes'] = $attributes;
}