2021-10-14 04:19:40 -04:00
< ? php
/**
2024-05-23 03:26:56 -04:00
* SPDX - FileCopyrightText : 2017 Nextcloud GmbH and Nextcloud contributors
* SPDX - License - Identifier : AGPL - 3.0 - or - later
2021-10-14 04:19:40 -04:00
*/
namespace OC\Contacts\ContactsMenu\Providers ;
2022-03-10 21:11:28 -05:00
use OC\Profile\ProfileManager ;
2021-10-14 04:19:40 -04:00
use OCP\Contacts\ContactsMenu\IActionFactory ;
use OCP\Contacts\ContactsMenu\IEntry ;
use OCP\Contacts\ContactsMenu\IProvider ;
use OCP\IURLGenerator ;
use OCP\IUserManager ;
use OCP\L10N\IFactory as IL10NFactory ;
class ProfileProvider implements IProvider {
public function __construct (
2023-06-25 04:26:58 -04:00
private IActionFactory $actionFactory ,
private ProfileManager $profileManager ,
private IL10NFactory $l10nFactory ,
private IURLGenerator $urlGenerator ,
private IUserManager $userManager ,
2021-10-14 04:19:40 -04:00
) {
}
2023-06-25 04:26:58 -04:00
public function process ( IEntry $entry ) : void {
2021-10-14 04:19:40 -04:00
$targetUserId = $entry -> getProperty ( 'UID' );
$targetUser = $this -> userManager -> get ( $targetUserId );
if ( ! empty ( $targetUser )) {
2022-03-10 21:11:28 -05:00
if ( $this -> profileManager -> isProfileEnabled ( $targetUser )) {
2021-10-14 04:19:40 -04:00
$iconUrl = $this -> urlGenerator -> getAbsoluteURL ( $this -> urlGenerator -> imagePath ( 'core' , 'actions/profile.svg' ));
2021-11-25 21:00:40 -05:00
$profileActionText = $this -> l10nFactory -> get ( 'lib' ) -> t ( 'View profile' );
2024-11-13 03:42:26 -05:00
$profileUrl = $this -> urlGenerator -> linkToRouteAbsolute ( 'profile.ProfilePage.index' , [ 'targetUserId' => $targetUserId ]);
2021-10-20 08:43:45 -04:00
$action = $this -> actionFactory -> newLinkAction ( $iconUrl , $profileActionText , $profileUrl , 'profile' );
2021-10-14 04:19:40 -04:00
// Set highest priority (by descending order), other actions have the default priority 10 as defined in lib/private/Contacts/ContactsMenu/Actions/LinkAction.php
$action -> setPriority ( 20 );
$entry -> addAction ( $action );
}
}
}
}