You are here

public function SocialSharePrivacy::services in Share Message 8

Prepare services for drupalSettings.

Return value

array Prepared services array.

1 call to SocialSharePrivacy::services()
SocialSharePrivacy::build in src/Plugin/sharemessage/SocialSharePrivacy.php
Creates the AddThis toolbar.

File

src/Plugin/sharemessage/SocialSharePrivacy.php, line 225

Class

SocialSharePrivacy
SocialSharePrivacy plugin.

Namespace

Drupal\sharemessage\Plugin\sharemessage

Code

public function services() {
  $all_services = [];
  foreach (array_keys(static::allServices()) as $service) {
    $all_services[$service]['status'] = FALSE;
  }
  $enabled_services = [];
  $library_discovery = \Drupal::service('library.discovery');
  $library = $library_discovery
    ->getLibraryByName('sharemessage', 'socialshareprivacy');
  if (!empty($library['library path'])) {
    $images_folder = $library['library path'] . '/images/';
  }
  else {
    $images_folder = 'libraries/socialshareprivacy/images/';
  }
  $services = $this->shareMessage
    ->getSetting('services') ?: $this->socialSharePrivacyConfig
    ->get('services');
  foreach ($services as $service) {
    $enabled_services[$service]['status'] = TRUE;
    if (in_array($service, array_keys($this
      ->servicesWithSettings()))) {
      $enabled_services[$service] = array_merge($enabled_services[$service], $this
        ->servicesWithSettings()[$service]);
    }
    if (in_array($service, [
      'mail',
      'tumblr',
      'fbshare',
    ])) {
      $enabled_services[$service]['line_img'] = file_create_url($images_folder . $service . '.png');
    }
    else {
      $enabled_services[$service]['dummy_line_img'] = file_create_url($images_folder . 'dummy_' . $service . '.png');
    }
  }
  return array_replace($all_services, $enabled_services);
}