Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RW-1058] Contributor fixes #958

Merged
merged 2 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 25 additions & 12 deletions html/modules/custom/reliefweb_entities/src/Entity/Report.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down
Loading