You are here

class AvatarKitDefaultPreferenceSubscriber in Avatar Kit 8.2

Subscriber for preference events.

Hierarchy

Expanded class hierarchy of AvatarKitDefaultPreferenceSubscriber

1 string reference to 'AvatarKitDefaultPreferenceSubscriber'
avatars.services.yml in ./avatars.services.yml
avatars.services.yml
1 service uses AvatarKitDefaultPreferenceSubscriber
avatars.service_preference.default in ./avatars.services.yml
Drupal\avatars\EventSubscriber\AvatarKitDefaultPreferenceSubscriber

File

src/EventSubscriber/AvatarKitDefaultPreferenceSubscriber.php, line 13

Namespace

Drupal\avatars\EventSubscriber
View source
class AvatarKitDefaultPreferenceSubscriber implements EventSubscriberInterface {

  /**
   * Sorts avatar services by config entity weight value.
   *
   * @param \Drupal\avatars\Event\EntityServicePreferenceEvent $event
   *   Entity service preference event.
   */
  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);
  }

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {
    $events[AvatarKitEvents::ENTITY_SERVICE_PREFERENCE][] = [
      'avatarServiceWeights',
      0,
    ];
    return $events;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AvatarKitDefaultPreferenceSubscriber::avatarServiceWeights public function Sorts avatar services by config entity weight value.
AvatarKitDefaultPreferenceSubscriber::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to.