Problem/Motivation

I am using the inline_entity_form_complex field widget configured to create new revisions. The new revisions get created and have the correct user and timestamp. However, the new revisions use the same revision log message as the previous revision of the entity, which usually means the revision log message is inaccurate.

Steps to reproduce

My current project uses the Revision Log Default module, which exposes this bug very well. If I create a new node via IEF and then edit it a couple times, we see that I keep getting the original revision log message:

bug

Proposed resolution

The InlineEntityForm element class has this snippet of code that sets the user and timestamp of the new revision:

      // @see \Drupal\Core\Entity\ContentEntityForm::buildEntity
      if ($entity_form['#entity'] instanceof RevisionLogInterface) {
        $entity_form['#entity']->setRevisionUserId(\Drupal::currentUser()->id());
        $entity_form['#entity']->setRevisionCreationTime(\Drupal::time()->getRequestTime());
      }

What it misses, though, is something that happens in the ::prepareEntity method of ContentEntityForm:

    // Hide the current revision log message in UI.
    if ($this->showRevisionUi() && !$this->entity->isNew() && $this->entity instanceof RevisionLogInterface) {
      $this->entity->setRevisionLogMessage(NULL);
    }

That's the line that prevents the latest revision log message from getting used over and over when using the basic entity form.

I think we should just throw that line into the ief code:

      // @see \Drupal\Core\Entity\ContentEntityForm::buildEntity and ::prepareEntity.
      if ($entity_form['#entity'] instanceof RevisionLogInterface) {
        $entity_form['#entity']->setRevisionLogMessage(NULL);
        $entity_form['#entity']->setRevisionUserId(\Drupal::currentUser()->id());
        $entity_form['#entity']->setRevisionCreationTime(\Drupal::time()->getRequestTime());
      }

With that little change, the revision log message no longer gets stuck.

fixed

Remaining tasks

User interface changes

API changes

Data model changes

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

danflanagan8 created an issue. See original summary.

danflanagan8’s picture

Status: Active » Needs review
peri22’s picture

Status: Needs review » Reviewed & tested by the community

I checked MR !176 against the '3.x' HEAD with a kernel test that edits an entity through an inline entity form with '#revision' enabled.

On HEAD, the new revision keeps the previous revision's log message. With the MR, it starts empty, and the earlier revision keeps its own.

The pipeline is green. RTBC.

dww’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests

Thanks for working on this!

Re: #4: Please add that Kernel test to the MR and make sure it passes in our GitLab CI world.

We generally don't commit anything to IEF anymore without tests (unless absolutely necessary).

Thanks again,
-Derek