Perform entity validation in bulk actions.

This commit is contained in:
Paul Weidner 2021-12-07 15:26:15 -08:00 committed by Michael Stenta
parent 61022ea0d2
commit f57399947d
4 changed files with 60 additions and 0 deletions

View File

@ -221,6 +221,22 @@ class AssetGroupActionForm extends ConfirmFormBase {
$log->get('status')->first()->applyTransitionById('done');
}
// Validate the log before saving.
$violations = $log->validate();
if ($violations->count() > 0) {
$this->messenger()->addWarning(
$this->t('Could not group assets: @bundle @entity_type validation failed.',
[
'@bundle' => $log->getBundleLabel(),
'@entity_type' => $log->getEntityType()->getSingularLabel(),
],
),
);
$this->tempStore->delete($this->currentUser()->id());
$form_state->setRedirectUrl($this->getCancelUrl());
return;
}
$log->save();
$this->messenger()->addMessage($this->t('Log created: <a href=":uri">%log_label</a>', [':uri' => $log->toUrl()->toString(), '%log_label' => $log->label()]));
}

View File

@ -233,6 +233,20 @@ class EntityFlagActionForm extends ConfirmFormBase {
$flag_field->appendItem($flag);
}
// Validate the entity before saving.
$violations = $entity->validate();
if ($violations->count() > 0) {
$this->messenger()->addWarning(
$this->t('Could not flag <a href=":entity_link">%entity_label</a>: validation failed.',
[
':entity_link' => $entity->toUrl()->setAbsolute()->toString(),
'%entity_label' => $entity->label(),
],
),
);
continue;
}
$entity->save();
$total_count++;
}

View File

@ -220,6 +220,22 @@ class AssetMoveActionForm extends ConfirmFormBase {
$log->get('status')->first()->applyTransitionById('done');
}
// Validate the log before saving.
$violations = $log->validate();
if ($violations->count() > 0) {
$this->messenger()->addWarning(
$this->t('Could not move assets: @bundle @entity_type validation failed.',
[
'@bundle' => $log->getBundleLabel(),
'@entity_type' => $log->getEntityType()->getSingularLabel(),
],
),
);
$this->tempStore->delete($this->currentUser()->id());
$form_state->setRedirectUrl($this->getCancelUrl());
return;
}
$log->save();
$this->messenger()->addMessage($this->t('Log created: <a href=":uri">%log_label</a>', [':uri' => $log->toUrl()->toString(), '%log_label' => $log->label()]));
}

View File

@ -215,6 +215,20 @@ class LogAssignActionForm extends ConfirmFormBase {
$owner_field->appendItem($owner);
}
// Validate the log before saving.
$violations = $entity->validate();
if ($violations->count() > 0) {
$this->messenger()->addWarning(
$this->t('Could not assign log <a href=":entity_link">%entity_label</a>: validation failed.',
[
':entity_link' => $entity->toUrl()->setAbsolute()->toString(),
'%entity_label' => $entity->label(),
],
),
);
continue;
}
$entity->save();
$total_count++;
}