1
0

EmailAction.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OC\Profile\Actions;
  8. use OCP\Accounts\IAccountManager;
  9. use OCP\IURLGenerator;
  10. use OCP\IUser;
  11. use OCP\L10N\IFactory;
  12. use OCP\Profile\ILinkAction;
  13. class EmailAction implements ILinkAction {
  14. private string $value = '';
  15. public function __construct(
  16. private IAccountManager $accountManager,
  17. private IFactory $l10nFactory,
  18. private IURLGenerator $urlGenerator,
  19. ) {
  20. }
  21. public function preload(IUser $targetUser): void {
  22. $account = $this->accountManager->getAccount($targetUser);
  23. $this->value = $account->getProperty(IAccountManager::PROPERTY_EMAIL)->getValue();
  24. }
  25. public function getAppId(): string {
  26. return 'core';
  27. }
  28. public function getId(): string {
  29. return IAccountManager::PROPERTY_EMAIL;
  30. }
  31. public function getDisplayId(): string {
  32. return $this->l10nFactory->get('lib')->t('Email');
  33. }
  34. public function getTitle(): string {
  35. return $this->l10nFactory->get('lib')->t('Mail %s', [$this->value]);
  36. }
  37. public function getPriority(): int {
  38. return 20;
  39. }
  40. public function getIcon(): string {
  41. return $this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/mail.svg'));
  42. }
  43. public function getTarget(): ?string {
  44. if (empty($this->value)) {
  45. return null;
  46. }
  47. return 'mailto:' . $this->value;
  48. }
  49. }