Perform entity validation in bulk actions.
This commit is contained in:
parent
61022ea0d2
commit
f57399947d
|
@ -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()]));
|
||||
}
|
||||
|
|
|
@ -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++;
|
||||
}
|
||||
|
|
|
@ -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()]));
|
||||
}
|
||||
|
|
|
@ -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++;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue