From 85cc1b34d1c5fcf620798e2bc0c24fe65630afc7 Mon Sep 17 00:00:00 2001 From: orakili Date: Wed, 4 Dec 2024 05:10:59 +0000 Subject: [PATCH 1/2] fix: status when unverified and allowed and add messages with the different user rights for the sources Refs: RW-1058 --- .../reliefweb_entities/src/Entity/Report.php | 37 +++++++++++++------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/html/modules/custom/reliefweb_entities/src/Entity/Report.php b/html/modules/custom/reliefweb_entities/src/Entity/Report.php index a19b0c181..d4dbc56be 100644 --- a/html/modules/custom/reliefweb_entities/src/Entity/Report.php +++ b/html/modules/custom/reliefweb_entities/src/Entity/Report.php @@ -400,9 +400,6 @@ protected function updateModerationStatusFromPostingRights() { // Blocked for some sources. if (!empty($rights[1])) { $status = 'refused'; - $message = strtr('Blocked user for @sources.', [ - '@sources' => implode(', ', TaxonomyHelper::getSourceShortnames($rights[1])), - ]); } // Trusted for all the sources. elseif (isset($rights[3]) && count($rights[3]) === count($sources)) { @@ -411,25 +408,41 @@ protected function updateModerationStatusFromPostingRights() { // Trusted for at least 1. elseif (isset($rights[3]) && count($rights[3]) > 0) { $status = 'to-review'; - $message = strtr('Allowed user for @sources.', [ - '@sources' => implode(', ', TaxonomyHelper::getSourceShortnames($rights[3])), - ]); } - // Allowed for at least 1. - elseif (isset($rights[2]) && count($rights[2]) > 0) { + // Allowed for all the sources. + elseif (isset($rights[2]) && count($rights[2]) === count($sources)) { $status = 'to-review'; } // Unverified for some sources. else { $status = 'pending'; - - $message = strtr('Unverified user for @sources.', [ - '@sources' => implode(', ', TaxonomyHelper::getSourceShortnames($rights[0])), - ]); } $this->setModerationStatus($status); + // Add messages indicating the posting rights for easier review. + $message = ''; + if (!empty($rights[1])) { + $message = trim($message . strtr(' Blocked user for @sources.', [ + '@sources' => implode(', ', TaxonomyHelper::getSourceShortnames($rights[1])), + ])); + } + if (!empty($rights[0])) { + $message = trim($message . strtr(' Unverified user for @sources.', [ + '@sources' => implode(', ', TaxonomyHelper::getSourceShortnames($rights[0])), + ])); + } + if (!empty($rights[2])) { + $message = trim($message . strtr(' Allowed user for @sources.', [ + '@sources' => implode(', ', TaxonomyHelper::getSourceShortnames($rights[2])), + ])); + } + if (!empty($rights[3])) { + $message = trim($message . strtr(' Trusted user for @sources.', [ + '@sources' => implode(', ', TaxonomyHelper::getSourceShortnames($rights[3])), + ])); + } + // Update the log message. if (!empty($message)) { $revision_log_field = $this->getEntityType() From 685a96179d53a38c2b6fe0a3b140bd091048ec54 Mon Sep 17 00:00:00 2001 From: orakili Date: Wed, 4 Dec 2024 05:12:05 +0000 Subject: [PATCH 2/2] fix: hide origin field but perserve validation of origin notes Refs: RW-1058 --- .../src/Services/ReportFormAlter.php | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/html/modules/custom/reliefweb_entities/src/Services/ReportFormAlter.php b/html/modules/custom/reliefweb_entities/src/Services/ReportFormAlter.php index 9c6fb964f..d52c58e15 100644 --- a/html/modules/custom/reliefweb_entities/src/Services/ReportFormAlter.php +++ b/html/modules/custom/reliefweb_entities/src/Services/ReportFormAlter.php @@ -66,10 +66,8 @@ protected function addBundleFormAlterations(array &$form, FormStateInterface $fo $this->alterHeadlineFields($form, $form_state); // Alter the origin fields, setting the origin notes as mandatory when - // 'URL' is selected, except for contributors. - if (!$this->currentUser->hasRole('contributor')) { - $this->alterOriginFields($form, $form_state); - } + // 'URL' is selected. + $this->alterOriginFields($form, $form_state); // Alter the OCHA product field, ensuring only 1 is selectable and making // mandatory when OCHA is selected as source or hidden otherwise. @@ -454,8 +452,15 @@ public function validateEmbargoDate(array $form, FormStateInterface &$form_state * Form state. */ protected function alterFieldsForContributors(array &$form, FormStateInterface $form_state) { - // Default to submit. - $form['field_origin']['widget']['#default_value'] = 1; + // Default to submit for new documents otherwise preserve the value, for + // example when editing a report created by an editor. + if ($form_state->getFormObject()?->getEntity()?->isNew() === TRUE) { + $form['field_origin']['widget']['#default_value'] = '1'; + } + // Change the field to 'hidden' to hide it while perserving its value so + // that the alteration and validation of the origin notes field still work. + // @see ::alterOriginFields() + $form['field_origin']['widget']['#type'] = 'hidden'; // Hide fields. $form['field_bury']['#access'] = FALSE;