class AvatarKitDefaultPreferenceSubscriber in Avatar Kit 8.2
Subscriber for preference events.
Hierarchy
- class \Drupal\avatars\EventSubscriber\AvatarKitDefaultPreferenceSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of AvatarKitDefaultPreferenceSubscriber
1 string reference to 'AvatarKitDefaultPreferenceSubscriber'
1 service uses AvatarKitDefaultPreferenceSubscriber
File
- src/
EventSubscriber/ AvatarKitDefaultPreferenceSubscriber.php, line 13
Namespace
Drupal\avatars\EventSubscriberView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AvatarKitDefaultPreferenceSubscriber:: |
public | function | Sorts avatar services by config entity weight value. | |
AvatarKitDefaultPreferenceSubscriber:: |
public static | function | Returns an array of event names this subscriber wants to listen to. |