You are here

public function AvatarKitDefaultPreferenceSubscriber::avatarServiceWeights in Avatar Kit 8.2

Sorts avatar services by config entity weight value.

Parameters

\Drupal\avatars\Event\EntityServicePreferenceEvent $event: Entity service preference event.

File

src/EventSubscriber/AvatarKitDefaultPreferenceSubscriber.php, line 21

Class

AvatarKitDefaultPreferenceSubscriber
Subscriber for preference events.

Namespace

Drupal\avatars\EventSubscriber

Code

public function avatarServiceWeights(EntityServicePreferenceEvent $event) {
  $service_ids = array_keys($event
    ->getServices());
  $services = AvatarKitService::loadMultiple($service_ids);

  // Sort by weight.
  uasort($services, [
    AvatarKitService::class,
    'sort',
  ]);
  $service_weights = array_flip(array_keys($services));
  $event
    ->setServices($service_weights);
}