Problem/Motivation

Reported here, the changes made to the widget are not applied if the entity is new.

Proposed resolution

Fix this.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Comments

Sam152 created an issue. See original summary.

Sam152 credited mtodor.

sam152’s picture

sam152’s picture

Status: Active » Needs review
StatusFileSize
new1.95 KB
new2.8 KB

Credited @mtodor for the original patch. Adding a test for this as well.

The fix itself looks good, restoring the default moderation state on $original_entity makes sense to me.

The last submitted patch, 4: 3065802-4-test-only.patch, failed testing. View results

alexpott’s picture

Status: Needs review » Needs work

The test and the change look good.

Looking at a fuller context of the change...

    // If the entity is not new, grab the most recent revision and
    // load it. The moderation state of the saved revision will be used
    // to display the current state as well determine the the appropriate
    // transitions.
    if (!$entity->isNew()) {
      /** @var \Drupal\Core\Entity\ContentEntityInterface $original_entity */
      $original_entity = $this->entityTypeManager->getStorage($entity->getEntityTypeId())->loadRevision($entity->getLoadedRevisionId());
      if (!$entity->isDefaultTranslation() && $original_entity->hasTranslation($entity->language()->getId())) {
        $original_entity = $original_entity->getTranslation($entity->language()->getId());
      }
    }
    else {
      $original_entity->set('moderation_state', $default->id());
    }

We need to either extend the comment above, Or (probably better) - add a comment above the else {.

sam152’s picture

Status: Needs work » Needs review
StatusFileSize
new1.87 KB

Thanks for the review, reflowed and rejigged both comments.

sam152’s picture

StatusFileSize
new3.97 KB

Whoops, and the patch.

chr.fritsch’s picture

Status: Needs review » Reviewed & tested by the community

This is ready to go

alexpott’s picture

Version: 8.8.x-dev » 8.7.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)

Committed 884786d and pushed to 8.8.x. Thanks!

Will backport to 8.7.x if the tests are green.

  • alexpott committed 884786d on 8.8.x
    Issue #3065802 by Sam152, mtodor, alexpott: Preview and content...
chr.fritsch’s picture

I think the backport should happen here https://www.drupal.org/project/drupal/issues/3065804

alexpott’s picture

Version: 8.7.x-dev » 8.8.x-dev
Status: Patch (to be ported) » Fixed
Related issues: +#3065804: Backport content moderation preview fixes to 8.7

Thanks @chr.fritsch

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.