Made everything have revisions all the time

This commit is contained in:
naomi 2022-04-03 17:01:19 +01:00
parent 13ddf5aa13
commit c3f802835f
7 changed files with 19 additions and 65 deletions

View File

@ -54,18 +54,9 @@ class OCCaseFeeForm extends ContentEntityForm {
*/ */
public function save(array $form, FormStateInterface $form_state) { public function save(array $form, FormStateInterface $form_state) {
$entity = $this->entity; $entity = $this->entity;
$entity->setNewRevision();
// Save as a new revision if requested to do so. $entity->setRevisionCreationTime(REQUEST_TIME);
if (!$form_state->isValueEmpty('new_revision') && $form_state->getValue('new_revision') != FALSE) { $entity->setRevisionUserId(\Drupal::currentUser()->id());
$entity->setNewRevision();
// If a new revision is created, save the current user as revision author.
$entity->setRevisionCreationTime($this->time->getRequestTime());
$entity->setRevisionUserId($this->account->id());
}
else {
$entity->setNewRevision(FALSE);
}
$status = parent::save($form, $form_state); $status = parent::save($form, $form_state);

View File

@ -38,18 +38,9 @@ class OCCaseForm extends ContentEntityForm {
*/ */
public function save(array $form, FormStateInterface $form_state) { public function save(array $form, FormStateInterface $form_state) {
$entity = $this->entity; $entity = $this->entity;
$entity->setNewRevision();
// Save as a new revision if requested to do so. $entity->setRevisionCreationTime(REQUEST_TIME);
if (!$form_state->isValueEmpty('new_revision') && $form_state->getValue('new_revision') != FALSE) { $entity->setRevisionUserId(\Drupal::currentUser()->id());
$entity->setNewRevision();
// If a new revision is created, save the current user as revision author.
$entity->setRevisionCreationTime( \Drupal::time()->getRequestTime());
$entity->setRevisionUserId(\Drupal::currentUser()->id());
}
else {
$entity->setNewRevision(FALSE);
}
$status = parent::save($form, $form_state); $status = parent::save($form, $form_state);

View File

@ -54,18 +54,9 @@ class OCCaseProvisionForm extends ContentEntityForm {
*/ */
public function save(array $form, FormStateInterface $form_state) { public function save(array $form, FormStateInterface $form_state) {
$entity = $this->entity; $entity = $this->entity;
$entity->setNewRevision();
// Save as a new revision if requested to do so. $entity->setRevisionCreationTime(REQUEST_TIME);
if (!$form_state->isValueEmpty('new_revision') && $form_state->getValue('new_revision') != FALSE) { $entity->setRevisionUserId(\Drupal::currentUser()->id());
$entity->setNewRevision();
// If a new revision is created, save the current user as revision author.
$entity->setRevisionCreationTime($this->time->getRequestTime());
$entity->setRevisionUserId($this->account->id());
}
else {
$entity->setNewRevision(FALSE);
}
$status = parent::save($form, $form_state); $status = parent::save($form, $form_state);

View File

@ -43,7 +43,8 @@ class OCActivityController extends ControllerBase implements ContainerInjectionI
*/ */
public function revisionPageTitle($oc_activity_revision) { public function revisionPageTitle($oc_activity_revision) {
$oc_activity = $this->entityTypeManager()->getStorage('oc_activity')->loadRevision($oc_activity_revision); $oc_activity = $this->entityTypeManager()->getStorage('oc_activity')->loadRevision($oc_activity_revision);
return $this->t('Revision of %title from %date', ['%title' => $oc_activity->label(), '%date' => format_date($oc_activity->getRevisionCreationTime())]); $date = \Drupal::service('date.formatter')->format($oc_activity->getRevisionCreationTime());
return $this->t('Revision of %title from %date', ['%title' => $oc_activity->label(), '%date' => $date]);
} }
/** /**

View File

@ -38,18 +38,9 @@ class OCActivityForm extends ContentEntityForm {
*/ */
public function save(array $form, FormStateInterface $form_state) { public function save(array $form, FormStateInterface $form_state) {
$entity = $this->entity; $entity = $this->entity;
$entity->setNewRevision();
// Save as a new revision if requested to do so. $entity->setRevisionCreationTime(REQUEST_TIME);
if (!$form_state->isValueEmpty('new_revision') && $form_state->getValue('new_revision') != FALSE) { $entity->setRevisionUserId(\Drupal::currentUser()->id());
$entity->setNewRevision();
// If a new revision is created, save the current user as revision author.
$entity->setRevisionCreationTime(REQUEST_TIME);
$entity->setRevisionUserId(\Drupal::currentUser()->id());
}
else {
$entity->setNewRevision(FALSE);
}
$status = parent::save($form, $form_state); $status = parent::save($form, $form_state);
@ -66,8 +57,8 @@ class OCActivityForm extends ContentEntityForm {
])); ]));
} }
// If you have unpublished the entity and you can't see unpublished entities, redirect to a more informative message than just "Access Denied". // If you have unpublished the entity and you can't see unpublished entities, redirect to a more informative message than just "Access Denied".
if (!$form_state->getValue('status')['value'] && !\Drupal::currentUser()->hasPermission('view unpublished activity entities')) { if (is_array($form_state->getValue('status')) && $form_state->getValue('status')['value'] == false && !\Drupal::currentUser()->hasPermission('view unpublished actor entities')) {
\Drupal::messenger()->addMessage($this->t('The %bundle is now unpublished & hidden from you.', [ \Drupal::messenger()->addMessage($this->t('The %bundle is now unpublished & hidden from you.', [
'%bundle' => $entity->bundle(), '%bundle' => $entity->bundle(),
])); ]));
$form_state->setRedirect('<front>'); $form_state->setRedirect('<front>');

View File

@ -38,8 +38,6 @@ class OCActorForm extends ContentEntityForm {
*/ */
public function save(array $form, FormStateInterface $form_state) { public function save(array $form, FormStateInterface $form_state) {
$entity = $this->entity; $entity = $this->entity;
// Always make a new revision for a person. They are not changed often and people are likely to
// want to know what has happened to them over time.
$entity->setNewRevision(); $entity->setNewRevision();
$entity->setRevisionCreationTime(REQUEST_TIME); $entity->setRevisionCreationTime(REQUEST_TIME);
$entity->setRevisionUserId(\Drupal::currentUser()->id()); $entity->setRevisionUserId(\Drupal::currentUser()->id());

View File

@ -54,18 +54,9 @@ class OCOrganisationForm extends ContentEntityForm {
*/ */
public function save(array $form, FormStateInterface $form_state) { public function save(array $form, FormStateInterface $form_state) {
$entity = $this->entity; $entity = $this->entity;
$entity->setNewRevision();
// Save as a new revision if requested to do so. $entity->setRevisionCreationTime(REQUEST_TIME);
if (!$form_state->isValueEmpty('new_revision') && $form_state->getValue('new_revision') != FALSE) { $entity->setRevisionUserId(\Drupal::currentUser()->id());
$entity->setNewRevision();
// If a new revision is created, save the current user as revision author.
$entity->setRevisionCreationTime($this->time->getRequestTime());
$entity->setRevisionUserId($this->account->id());
}
else {
$entity->setNewRevision(FALSE);
}
$status = parent::save($form, $form_state); $status = parent::save($form, $form_state);