ProfileProvider.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. namespace OC\Contacts\ContactsMenu\Providers;
  7. use OC\Profile\ProfileManager;
  8. use OCP\Contacts\ContactsMenu\IActionFactory;
  9. use OCP\Contacts\ContactsMenu\IEntry;
  10. use OCP\Contacts\ContactsMenu\IProvider;
  11. use OCP\IURLGenerator;
  12. use OCP\IUserManager;
  13. use OCP\L10N\IFactory as IL10NFactory;
  14. class ProfileProvider implements IProvider {
  15. public function __construct(
  16. private IActionFactory $actionFactory,
  17. private ProfileManager $profileManager,
  18. private IL10NFactory $l10nFactory,
  19. private IURLGenerator $urlGenerator,
  20. private IUserManager $userManager,
  21. ) {
  22. }
  23. public function process(IEntry $entry): void {
  24. $targetUserId = $entry->getProperty('UID');
  25. $targetUser = $this->userManager->get($targetUserId);
  26. if (!empty($targetUser)) {
  27. if ($this->profileManager->isProfileEnabled($targetUser)) {
  28. $iconUrl = $this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/profile.svg'));
  29. $profileActionText = $this->l10nFactory->get('lib')->t('View profile');
  30. $profileUrl = $this->urlGenerator->linkToRouteAbsolute('profile.ProfilePage.index', ['targetUserId' => $targetUserId]);
  31. $action = $this->actionFactory->newLinkAction($iconUrl, $profileActionText, $profileUrl, 'profile');
  32. // Set highest priority (by descending order), other actions have the default priority 10 as defined in lib/private/Contacts/ContactsMenu/Actions/LinkAction.php
  33. $action->setPriority(20);
  34. $entry->addAction($action);
  35. }
  36. }
  37. }
  38. }