You are here

class SocialPostHelper in Open Social 10.2.x

Same name and namespace in other branches
  1. 10.3.x modules/social_features/social_post/src/Service/SocialPostHelper.php \Drupal\social_post\Service\SocialPostHelper
  2. 10.0.x modules/social_features/social_post/src/Service/SocialPostHelper.php \Drupal\social_post\Service\SocialPostHelper
  3. 10.1.x modules/social_features/social_post/src/Service/SocialPostHelper.php \Drupal\social_post\Service\SocialPostHelper

Class SocialPostHelper.

@package Drupal\social_post\Service

Hierarchy

Expanded class hierarchy of SocialPostHelper

1 string reference to 'SocialPostHelper'
social_post.services.yml in modules/social_features/social_post/social_post.services.yml
modules/social_features/social_post/social_post.services.yml
1 service uses SocialPostHelper
social_post.helper in modules/social_features/social_post/social_post.services.yml
Drupal\social_post\Service\SocialPostHelper

File

modules/social_features/social_post/src/Service/SocialPostHelper.php, line 13

Namespace

Drupal\social_post\Service
View source
class SocialPostHelper implements SocialPostHelperInterface {

  /**
   * The entity type manager.
   *
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  protected $entityTypeManager;

  /**
   * The current active user.
   *
   * @var \Drupal\Core\Session\AccountProxyInterface
   */
  protected $currentUser;

  /**
   * SocialPostHelper constructor.
   *
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   The entity type manager.
   * @param \Drupal\Core\Session\AccountProxyInterface $current_user
   *   The current active user.
   */
  public function __construct(EntityTypeManagerInterface $entity_type_manager, AccountProxyInterface $current_user) {
    $this->entityTypeManager = $entity_type_manager;
    $this->currentUser = $current_user;
  }

  /**
   * {@inheritdoc}
   */
  public function buildCurrentUserImage() {
    $storage = $this->entityTypeManager
      ->getStorage('profile');
    if (!empty($storage)) {

      // Load current user.
      $account = $this->currentUser
        ->getAccount();
      if ($user_profile = $storage
        ->loadByUser($account, 'profile')) {

        // Load compact notification view mode of the attached profile.
        return $this->entityTypeManager
          ->getViewBuilder('profile')
          ->view($user_profile, 'compact_notification');
      }
    }
    return NULL;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
SocialPostHelper::$currentUser protected property The current active user.
SocialPostHelper::$entityTypeManager protected property The entity type manager.
SocialPostHelper::buildCurrentUserImage public function Gets image of the user profile. Overrides SocialPostHelperInterface::buildCurrentUserImage
SocialPostHelper::__construct public function SocialPostHelper constructor.