Problem/Motivation

When weight fields are updated via a view using a WeightSelector field, the entity changed date is updated, but no new revision is created. Previous revision user is retained regardless of who made the change via the view.

It would be nice to have the option to create a new revision to track such changes.

Steps to reproduce

Update weight field(s) via a view using WeightSelector. Note that affected entities show as recently updated, but no new revisions are created, and there is no indication of who made the change.

Proposed resolution

1) Add an option to the WeightSelector field to allow creation of a new revision. A default value of FALSE avoids changing current functionality.
2) If the option is selected, create a new revision when saving the affected entity.

Update WeightSelector::viewsFormSubmit() with something along the lines of:

...
$entity->set($field_name, $row['weight']);
if ($this->options['new_revision']) {
  $entity->setNewRevision(TRUE);
  $entity->revision_log = 'Updated ' . $entity->get($field_name)->getFieldDefinition()->getLabel();
  $entity->setRevisionCreationTime(\Drupal::time()->getCurrentTime());
  $entity->setRevisionUserId(\Drupal::currentUser()->id());
}
$entity->save();
...

Remaining tasks

  • Write a patch
  • Review
  • Commit

User interface changes

Add 'Create new revision' option for the WeightSelector view field.

Issue fork weight-3356412

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

justcaldwell created an issue. See original summary.

justcaldwell’s picture

Per #2671352: Add a method for checking if an entity allow revisions, we may need to ensure revisions are enabled before calling $entity->setNewRevision(TRUE).

justcaldwell’s picture

Issue summary: View changes

justcaldwell’s picture

Status: Active » Needs review