ProfileLabelSubscriber.php in Open Social 10.3.x
Same filename and directory in other branches
- 8.9 modules/social_features/social_profile/src/EventSubscriber/ProfileLabelSubscriber.php
 - 8 modules/social_features/social_profile/src/EventSubscriber/ProfileLabelSubscriber.php
 - 8.2 modules/social_features/social_profile/src/EventSubscriber/ProfileLabelSubscriber.php
 - 8.3 modules/social_features/social_profile/src/EventSubscriber/ProfileLabelSubscriber.php
 - 8.4 modules/social_features/social_profile/src/EventSubscriber/ProfileLabelSubscriber.php
 - 8.5 modules/social_features/social_profile/src/EventSubscriber/ProfileLabelSubscriber.php
 - 8.6 modules/social_features/social_profile/src/EventSubscriber/ProfileLabelSubscriber.php
 - 8.7 modules/social_features/social_profile/src/EventSubscriber/ProfileLabelSubscriber.php
 - 8.8 modules/social_features/social_profile/src/EventSubscriber/ProfileLabelSubscriber.php
 - 10.0.x modules/social_features/social_profile/src/EventSubscriber/ProfileLabelSubscriber.php
 - 10.1.x modules/social_features/social_profile/src/EventSubscriber/ProfileLabelSubscriber.php
 - 10.2.x modules/social_features/social_profile/src/EventSubscriber/ProfileLabelSubscriber.php
 
Namespace
Drupal\social_profile\EventSubscriberFile
modules/social_features/social_profile/src/EventSubscriber/ProfileLabelSubscriber.phpView source
<?php
namespace Drupal\social_profile\EventSubscriber;
use Drupal\profile\Entity\Profile;
use Drupal\profile\Event\ProfileEvents;
use Drupal\profile\Event\ProfileLabelEvent;
use Drupal\user\Entity\User;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
 * Class ProfileLabelSubscriber.
 *
 * @package Drupal\social_profile\EventSubscriber
 */
class ProfileLabelSubscriber implements EventSubscriberInterface {
  /**
   * Get the label event.
   *
   * @return mixed
   *   Returns request events.
   */
  public static function getSubscribedEvents() {
    $events[ProfileEvents::PROFILE_LABEL][] = [
      'overrideProfileLabel',
    ];
    return $events;
  }
  /**
   * Subscriber Callback for the event.
   *
   * @param \Drupal\profile\Event\ProfileLabelEvent $event
   *   The event.
   */
  public function overrideProfileLabel(ProfileLabelEvent $event) {
    $profile = $event
      ->getProfile();
    if ($profile instanceof Profile) {
      $account = User::load($profile
        ->getOwnerId());
      if ($account instanceof User) {
        $label = t('Profile of @name', [
          '@name' => $account
            ->getDisplayName(),
        ]);
        $event
          ->setLabel($label);
      }
    }
  }
}Classes
| 
            Name | 
                  Description | 
|---|---|
| ProfileLabelSubscriber | Class ProfileLabelSubscriber. |