+ /**
+ * Get the email field as a task link, if not on hold or set to do_not_email.
+ *
+ * @param string $email
+ *
+ * @return string
+ * @throws \API_Exception
+ * @throws \Civi\API\Exception\UnauthorizedException
+ */
+ protected function getLinkedEmail($email): string {
+ if (!$email) {
+ return '';
+ }
+ $emailID = Email::get()->setOrderBy(['is_primary' => 'DESC'])->setWhere([['contact_id', '=', $this->_id], ['email', '=', $email], ['on_hold', '=', FALSE], ['contact_id.is_deceased', '=', FALSE], ['contact_id.is_deleted', '=', FALSE], ['contact_id.do_not_email', '=', FALSE]])->execute()->first()['id'];
+ if (!$emailID) {
+ return $email;
+ }
+ $emailPopupUrl = CRM_Utils_System::url('civicrm/activity/email/add', [
+ 'action' => 'add',
+ 'reset' => '1',
+ 'email_id' => $emailID,
+ ], TRUE);
+
+ return '<a class="crm-popup" href="' . $emailPopupUrl . '">' . $email . '</a>';
+ }
+
+ /**
+ * Get the email fields from within the fields array.
+ *
+ * @param array $fields
+ */
+ protected function getEmailFields(array $fields): array {
+ $emailFields = [];
+ foreach (array_keys($fields) as $fieldName) {
+ if (substr($fieldName, 0, 6) === 'email-'
+ && (is_numeric(substr($fieldName, 6)) || substr($fieldName, 6) ===
+ 'Primary')) {
+ $emailFields[] = $fieldName;
+ }
+ }
+ return $emailFields;
+ }
+