Olepsava kode in prevodi.

pull/42/head
Lio Novelli 2024-03-10 22:33:47 +01:00
parent 296398da36
commit 3e527de407
3 changed files with 105 additions and 48 deletions

View File

@ -1,4 +1,41 @@
# Slovenian translations for yufu_admin module
#
msgid "jsonapi Output"
msgstr "Izpljunek jsonapija"
msgid "[YUFU] New concept draft: @title"
msgstr "[YUFU] Nov osnutek pojma: @title"
msgid "[YUFU] Your concept (changes) were approved: @title"
msgstr "[YUFU] Tvoj predlog sprememb pojma @title je bil potrjen."
msgid "[YUFU] Your concept (changes) were rejected: @title"
msgstr "[YUFU] Tvoj predlog sprememb pojma @title je bil zavržen"
msgid "New concept created: @title - @url"
msgstr "Ustvrjen je bil nov pojem @title - @url"
msgid "For transition @transition of concept @title (@nid) to recipients @recipients."
msgstr "Za tranzicijo @transition koncepta @title (@nid) prejemnikom @recipients."
msgid "Unknown"
msgstr "Neznan"
msgid "There was a problem sending your message and it was not sent. "
msgstr "Prišlo je do problema pri pošiljanju e-poštnega sporočila in le no ni bilo poslano. "
msgid "Your message has been sent. "
msgstr "E-poštno sporočilo je bilo poslano. "
msgid "@editor (@uid) is missing email."
msgstr "Urednik @editor (@uid) nima nastavljenega emaila."
msgid "New concept created: @title - @url"
msgstr "Ustvarjen je bil nov koncept: @title - @url"
msgid "Published changes not attributed to any of knownn users: @title - @url"
msgstr "Potrjene spremembe ne pripadajo nobenemu znanemu uporabniku: @title - @url"
msgid "There was a problem sending your message and it was not sent. For transition @transition."
msgstr "Prišlo je do problema pri pošiljanju e-poštnega sporočila in le to ni bilo poslano. Za tranzicijo @transition"

View File

@ -39,17 +39,17 @@ function yufu_admin_mail($key, &$message, $params) {
switch ($key) {
case 'concept_drafted':
$message['from'] = \Drupal::config('system.site')->get('mail');
$message['subject'] = t('YUFU: New concept draft: @title', ['@title' => $params['node_title']], $options);
$message['subject'] = t('[YUFU] New concept draft: @title', ['@title' => $params['node_title']], $options);
$message['body'][] = $params['message'];
break;
case 'concept_approved':
$message['from'] = \Drupal::config('system.site')->get('mail');
$message['subject'] = t('YUFU: Your concept (changes) were approved: @title', ['@title' => $params['node_title']], $options);
$message['subject'] = t('[YUFU] Your concept (changes) were approved: @title', ['@title' => $params['node_title']], $options);
$message['body'][] = $params['message'];
break;
case 'concept_rejected':
$message['from'] = \Drupal::config('system.site')->get('mail');
$message['subject'] = t('YUFU: Your concept (changes) were rejected: @title', ['@title' => $params['node_title']], $options);
$message['subject'] = t('[YUFU] Your concept (changes) were rejected: @title', ['@title' => $params['node_title']], $options);
$message['body'][] = $params['message'];
}
}
@ -70,17 +70,22 @@ function yufu_admin_node_presave(EntityInterface $entity) {
case 'stay_draft':
case 'concept_drafted':
// Send email to editors.
_yufu_admin_concept_drafted_mail($entity);
$params = _yufu_admin_concept_drafted_mail($entity);
$result = _yufu_admin_send_email($transition, $params['to'], $params);
_yufu_admin_status_message($result['result'], $transition, $entity, $params['to']);
break;
case 'concept_approved':
// Send email to revision creator (user).
// @TODO Maybe notify other editors.
_yufu_admin_concept_approved_send_mail($entity);
$params = _yufu_admin_concept_approved_get_message($entity);
$result = _yufu_admin_send_email($transition, $params['to'], $params);
_yufu_admin_status_message($result['result'], $transition, $entity, $params['to']);
break;
case 'concept_rejectd':
// Send email to revision creator (user).
// This transition happens on revision delete.
// Curently it is dead.
// @TODO https://git.kompot.si/yufu/manifest/issues/45
break;
}
}
@ -121,33 +126,56 @@ function _yufu_admin_get_node_transition(NodeInterface $node) {
* Concept node that was transitioned into published state.
*/
function _yufu_admin_concept_drafted_mail(NodeInterface $node) {
$mailManager = \Drupal::service('plugin.manager.mail');
$module = 'yufu_admin';
// @TODO - key doesn't need to be defined again.
$key = 'concept_drafted';
// To all editors.
$to = _yufu_admin_get_all_editors_emails();
$params['message'] = t('New concept created: @title - @url', [
'@title' => $node->getTitle(),
'@url' => $node->toUrl()->toString(),
'@url' => !$node->isNew() ? $node?->toUrl()?->toString() : '',
]);
$params['node_title'] = $node->getTitle();
$langcode = \Drupal::currentUser()->getPreferredLangcode();
$send = true;
$params['to'] = implode(',', $to);
return $params;
}
/**
* Function for sending emails.
*
* @param string $key
* Transition of a concept.
* @param string $to
* List of recipients.
* @param array $params
* Message parameters.
*
* @return array
* Mail manager response.
*/
function _yufu_admin_send_email($key = '', $to = '', $params = []) {
$mailManager = \Drupal::service('plugin.manager.mail');
$module = 'yufu_admin';
$langcode = \Drupal::currentUser()->getPreferredLangcode();
$send = TRUE;
$result = $mailManager->mail($module, $key, $to, $langcode, $params, NULL, $send);
// @TODO: Remove code duplications (_yufu_admin_concept_approved_send_mail).
if ($result['result'] !== true) {
Drupal::logger('yufu_admin')->error(t('There was a problem sending your message and it was not sent. For transition @transition.', [
'@transition' => $key,
]), 'error');
Drupal::messenger()->addError(t('There was a problem sending your message and it was not sent. For transition @transition.', [
'@transition' => $key,
]), 'error');
}
/**
* Add notifications on sending of emails.
*/
function _yufu_admin_status_message($result, $transition = '', $node = NULL, $recipients = '') {
$log = t('For transition @transition of concept @title (@nid) to recipients @recipients.', [
'@transition' => $transition,
'@title' => $node?->getTitle() ?? t('Unknown'),
'@nid' => $node?->id() ?? '',
'@recipients' => $recipients,
]);
if ($result !== TRUE) {
$message = t('There was a problem sending your message and it was not sent. ');
Drupal::logger('yufu_admin')->error($message . $log);
Drupal::messenger()->addError($message . $log);
}
else {
Drupal::logger('yufu_admin')->notice(t('Your message has been sent.'));
Drupal::messenger()->addStatus(t('Your message has been sent.'));
$message = t('Your message has been sent. ');
Drupal::logger('yufu_admin')->notice($message . $log);
Drupal::messenger()->addStatus($message . $log);
}
}
@ -168,7 +196,15 @@ function _yufu_admin_get_all_editors_emails() {
$emails = [];
foreach ($editors as $editor) {
/* @var \Drupal\user\UserInterface $user */
$emails[] = $editor->getEmail();
if ($email = $editor?->getEmail()) {
$emails[] = $email;
}
else {
\Drupal::logger('yufu_admin')->warning('@editor (@uid) is missing email.',[
'@editor' => $editor?->getDisplayName() ?? '',
'@uid' => $editor->id(),
]);
}
}
return $emails;
}
@ -179,44 +215,27 @@ function _yufu_admin_get_all_editors_emails() {
* @param \Drupal\node\NodeInterface $node
* Concept node that was transitioned into published state.
*/
function _yufu_admin_concept_approved_send_mail(NodeInterface $node) {
$mailManager = \Drupal::service('plugin.manager.mail');
$module = 'yufu_admin';
// @TODO - key doesn't need to be defined again.
$key = 'concept_approved';
function _yufu_admin_concept_approved_get_message(NodeInterface $node) {
// To the revision's authors.
// @TODO - to make this work properly, we should get a list of all authors of
// unpublished revisions so far since the last published revision.
if ($to = _yufu_admin_get_pioneer_email($node)) {
// @TODO Dodamo se avtorja v sporocilo?
$params['message'] = t('New concept created: @title - @url', [
'@title' => $node->getTitle(),
'@url' => $node->toUrl()->toString(),
'@url' => $node?->toUrl()?->toString() ?? '',
]);
}
else {
$to = implode(',', _yufu_admin_get_all_editors_emails());
$params['message'] = t('Published changes not attributed to any of knownn users: @title - @url', [
'title' => $node->getTitle(),
'url' => $node->toUrl()->toString(),
'@title' => $node->getTitle(),
'@url' => !$node->isNew() ? $node?->toUrl()?->toString() : '',
]);
}
$params['node_title'] = $node->getTitle();
$langcode = \Drupal::currentUser()->getPreferredLangcode();
$send = TRUE;
$result = $mailManager->mail($module, $key, $to, $langcode, $params, NULL, $send);
if ($result['result'] !== TRUE) {
Drupal::logger('yufu_admin')->error(t('There was a problem sending your message and it was not sent. For transition @transition.', [
'@transition' => $key,
]), 'error');
Drupal::messenger()->addError(t('There was a problem sending your message and it was not sent. For transition @transition.', [
'@transition' => $key,
]), 'error');
}
else {
Drupal::logger('yufu_admin')->notice(t('Your message has been sent.'));
Drupal::messenger()->addStatus(t('Your message has been sent.'));
}
$params['to'] = $to;
return $params;
}
/**

View File

@ -127,6 +127,7 @@ class AddConcept extends ResourceBase {
$concept->isDefaultRevision(FALSE);
$concept->setRevisionLogMessage('New revision by concept endpoint.');
$concept->moderation_state->target_id = 'draft';
$concept->setUnpublished();
$concept->save();
$this->logger->notice('New concept @title revision @revid created by uid @uid.', [
'@title' => $concept->getTitle(),