You are here

public function SocialMediaLinksPlatformManager::getPlatformsWithValue in Social Media Links Block and Field 8.2

The the platform plugins that have values.

Return value

array The platform plugins that have values.

File

src/SocialMediaLinksPlatformManager.php, line 85

Class

SocialMediaLinksPlatformManager
Manager class for the platform plugins.

Namespace

Drupal\social_media_links

Code

public function getPlatformsWithValue(array $platforms, $sort = TRUE) {
  $usedPlatforms = [];
  foreach ($this
    ->getPlatforms() as $platform_id => $platform) {
    if (!empty($platforms[$platform_id]['value'])) {
      $platform['instance']
        ->setValue($platforms[$platform_id]['value']);
      if (!empty($platforms[$platform_id]['description'])) {
        $platform['instance']
          ->setDescription($platforms[$platform_id]['description']);
      }
      $usedPlatforms[$platform_id] = $platform;
      $usedPlatforms[$platform_id]['weight'] = $platforms[$platform_id]['weight'];
      $usedPlatforms[$platform_id]['url'] = $platform['instance']
        ->generateUrl($platform['instance']
        ->getUrl());
    }
  }
  if ($sort) {
    uasort($usedPlatforms, [
      'Drupal\\Component\\Utility\\SortArray',
      'sortByWeightElement',
    ]);
  }
  return $usedPlatforms;
}