You are here

function sharemessage_get_addthis_services in Share Message 8

Same name and namespace in other branches
  1. 7 sharemessage.module \sharemessage_get_addthis_services()

Load AddThis services.

2 calls to sharemessage_get_addthis_services()
Addthis::buildConfigurationForm in src/Plugin/sharemessage/Addthis.php
Form constructor.
AddthisSettingsForm::buildForm in src/Form/AddthisSettingsForm.php
Form constructor.

File

./sharemessage.module, line 160
New Sharing Module.

Code

function sharemessage_get_addthis_services() {
  $options =& drupal_static(__FUNCTION__);
  if (!isset($options)) {
    if ($cache = \Drupal::cache()
      ->get('sharemessage_addthis_services:' . \Drupal::languageManager()
      ->getCurrentLanguage()
      ->getId())) {
      $options = $cache->data;
    }
    else {
      $json = addthis_get_services_json();
      $output = json_decode($json);
      if (!empty($output)) {
        $options = [
          (string) t('Common') => [],
          (string) t('Mail') => [],
          (string) t('Other') => [],
        ];
        foreach ($output->data as $service) {
          if (in_array($service->code, [
            'facebook',
            'facebook_like',
            'twitter',
            'xing',
            'linkedin',
            'wordpress',
            'google_plusone_share',
          ])) {
            $options[(string) t('Common')][$service->code] = $service->name;
          }
          elseif (in_array($service->code, [
            'mail',
            'gmail',
            'yahoomail',
            'aolmail',
            'email',
            'mailto',
          ])) {
            $options[(string) t('Mail')][$service->code] = $service->name;
          }
          else {
            $options[(string) t('Other')][$service->code] = $service->name;
          }
        }

        // Tweet is not defined?
        $options[(string) t('Common')]['tweet'] = t('Tweet');

        // Neither is Pinterest Follow.
        $options[(string) t('Common')]['pinterest_follow'] = t('Pinterest follow');
        \Drupal::cache()
          ->set('sharemessage_addthis_services:' . \Drupal::languageManager()
          ->getCurrentLanguage()
          ->getId(), $options);
      }
      else {
        \Drupal::cache()
          ->delete('sharemessage_addthis_services:' . \Drupal::languageManager()
          ->getCurrentLanguage()
          ->getId());
      }
    }
  }
  return $options;
}