Problem/Motivation

The revision log message form component is missing from the override layout entity form.

This is happening because Drupal\layout_builder\Form\OverridesEntityForm::init() currently uses Drupal\Core\Entity\Entity\EntityFormDisplay::collectRenderDisplay() with the $default_fallback parameter set to FALSE to load the entity $form_display. This removes the original components of the entity display form which includes the revision_log component.

Proposed resolution

  • Update Drupal\layout_builder\Form\OverridesEntityForm::init() to add the revision_log_message_form_item component to the entity $form_display if ContentEntityForm::showRevisionUi() is TRUE.
  • Add test(s).

Remaining tasks

Answer #36.2

User interface changes

Revision log message form is displayed on layout override form for entity types that support revisioning.

API changes

None.

Data model changes

None.

Release notes snippet

Update Layout Builder entity overrides form to display revision log message form when appropriate.

Original report by johnwebdev

With #3004536: Move the Layout Builder UI into an entity form for better integration with other content authoring modules and core features now being committed we have the Revision UI in the Layout Builder UI and when you save an override layout a new revision is created.

However, if you untick the "Create new revision" checkbox, a new revision is created anyway.

Secondly, you're not able to write a revision message.

Issue fork drupal-3033516

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

johndevman created an issue. See original summary.

johnwebdev’s picture

Status: Active » Closed (cannot reproduce)

Me and phenaproxima manually tested this in #2937199: Track Layout override revisions on entities which support revisioning today, closing this issue as 'cannot reproduce'.

mrweiner’s picture

Priority: Normal » Major
Status: Closed (cannot reproduce) » Active

Re-opening as I'm experiencing the same issue where there is no revision log field is present at all. Furthermore I opened up a Drupal Answers post and received confirmation of the bug from a user over there:

I did create a clean Drupal 8 instance, enabled Layout Builder for the basic page content type with enabled revisions.
I saw the same exact behaviour. Additionally, log messages were only saved with "edit" form and not with the "layout" form. So, it is definitely a core layout builder module bug and not related to the distribution you're using.

The distribution noted above is the Lightning Distro, but that doesn't appear to be the culprit. Marking Major as it completely breaks revisions related to Layout Builder.

ismail cherri’s picture

I think I found the source of this bug.
In Drupal\layout_builder\Form\OverridesEntityForm class, the init() loads the entity $form_display using collectRenderDisplay method with the default_fallback set to FALSE, thus it removes the original components of the Node Display Form including the 'revision_log' component.

/**
   * {@inheritdoc}
   */
  protected function init(FormStateInterface $form_state) {
    parent::init($form_state);

    $form_display = EntityFormDisplay::collectRenderDisplay($this->entity, $this->getOperation(), FALSE);
    $form_display->setComponent(OverridesSectionStorage::FIELD_NAME, [
      'type' => 'layout_builder_widget',
      'weight' => -10,
      'settings' => [],
    ]);

    $this->setFormDisplay($form_display, $form_state);
  }

I think at this stage, the OverridesEntityForm should check if the entity implements \Drupal\Core\Entity\RevisionLogInterface and accordingly sets the component for 'revision_log'.

twfahey’s picture

Status: Active » Needs review
StatusFileSize
new1.05 KB

This patch I believe needs some work, but it is working for me on node entities, to add the log message when creating layout.

Status: Needs review » Needs work
tim.plunkett’s picture

Version: 8.7.x-dev » 8.8.x-dev
Issue tags: +Blocks-Layouts, +Needs tests

Oh I wish we'd had test coverage. This was definitely working before, but that change to collectRenderDisplay indeed broke it.

One note:

+++ b/core/modules/layout_builder/src/Form/OverridesEntityForm.php
@@ -88,6 +88,14 @@ protected function init(FormStateInterface $form_state) {
+    $section_storage = $form_state->getBuildInfo()['callback_object']->getSectionStorage();

$form_state->getBuildInfo()['callback_object'] is equivalent to $this here, so this can be $section_storage = $this->getSectionStorage();

twfahey’s picture

Cool - as Ismail Cherri pointed out, we should check to see that the entity type is revisionable, so added that check in using the `isRevisionable()` method, which I *think* we can rely safely on here.

ismail cherri’s picture

@twfahey If I may add, I don't think you need to get the Entity through the section storage at this point because $this->entity is already defined and it is used before your added code.

twfahey’s picture

Good call - simplified in latest patch, and adding initial testing.

twfahey’s picture

twfahey’s picture

Remove unused modules and body.

twfahey’s picture

Status: Needs work » Needs review
twfahey’s picture

Realized I wasn't asserting the block text had reverted back to the original text.

borisson_’s picture

Status: Needs review » Needs work

Setting this back to needs work for the nitpick, but I could only find that really small issue here, overall this is looking really good and it looks like it has sufficient (functional) coverage.

+++ b/core/modules/layout_builder/src/Form/OverridesEntityForm.php
@@ -88,6 +88,14 @@ protected function init(FormStateInterface $form_state) {
+      $form_display->setComponent($revision_log_message_form_item, $log_field_revision_message_form_data);  ¶

Übernit: this adds unneeded whitespace at the end of the line, can we remove that?

yogeshmpawar’s picture

Assigned: Unassigned » yogeshmpawar
yogeshmpawar’s picture

Assigned: yogeshmpawar » Unassigned
Status: Needs work » Needs review
StatusFileSize
new4.48 KB
new965 bytes

Comments addressed in #15 & added an interdiff as well.

borisson_’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs tests

Removed the needs tests tag because it seems like there is sufficient coverage now. My only nitpick also has been resolved.

adam-delaney’s picture

This patch works as expected. Applied cleanly against core 8.7.3.

tim.plunkett’s picture

  1. +++ b/core/modules/layout_builder/src/Form/OverridesEntityForm.php
    @@ -88,6 +88,14 @@ protected function init(FormStateInterface $form_state) {
    +    if ($entity_type->isRevisionable()) {
    +      $revision_log_message_form_item = $entity_type->getRevisionMetadataKey('revision_log_message');
    

    The getRevisionMetadataKey method is only on \Drupal\Core\Entity\ContentEntityTypeInterface so in theory this needs an instanceof check...

    The isRevisionable check worries me. It shouldn't be necessary if there's a revision metadata key. Also, are we sure this is all that is needed? Are there more checks needed?

  2. +++ b/core/modules/layout_builder/src/Form/OverridesEntityForm.php
    @@ -88,6 +88,14 @@ protected function init(FormStateInterface $form_state) {
    +      $log_field_revision_message_form_data = $log_field_definition->getDisplayOptions('form');
    +      $form_display->setComponent($revision_log_message_form_item, $log_field_revision_message_form_data);
    

    Will this respect the individual options as set up in the baseFieldDefinitions methods? For example, MenuLinkContent hides this

alexpott’s picture

Status: Reviewed & tested by the community » Needs review

Looks like we need answers to #20.

tim.plunkett’s picture

Status: Needs review » Needs work

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

joegraduate’s picture

Assigned: Unassigned » joegraduate
joegraduate’s picture

Assigned: joegraduate » Unassigned
Status: Needs work » Needs review
StatusFileSize
new1.16 KB
new4.83 KB

The attached patch addresses the questions/concerns raised by @tim.plunkett in #20:

The getRevisionMetadataKey method is only on \Drupal\Core\Entity\ContentEntityTypeInterface so in theory this needs an instanceof check...

Added instanceof check.

The isRevisionable check worries me. It shouldn't be necessary if there's a revision metadata key. Also, are we sure this is all that is needed? Are there more checks needed?

Replaced isRevisionable() with showRevisionUi() which also checks the $show_revision_ui property on the EntityType plugin.

Will this respect the individual options as set up in the baseFieldDefinitions methods? For example, MenuLinkContent hides this

I believe using showRevisionUi() instead of isRevisionable() should prevent this from doing anything for EntityType plugins like MenuLinkContent that haven't explicitly enabled the $show_revision_ui property.

Status: Needs review » Needs work

The last submitted patch, 26: 3033516-26.patch, failed testing. View results

joegraduate’s picture

Assigned: Unassigned » joegraduate
Status: Needs work » Needs review
joegraduate’s picture

Status: Needs review » Needs work
joegraduate’s picture

Assigned: joegraduate » Unassigned
Status: Needs work » Needs review
StatusFileSize
new709 bytes
new4.91 KB

Added defaultTheme property and setup method return typehint to LayoutBuilderRevisionTest.

johnwebdev’s picture

Status: Needs review » Needs work
Issue tags: +Needs issue summary update

I think we need a issue summary update here.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

james hawthorn-byng’s picture

Patch from comment #30 works for me

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

luke.leber’s picture

+1 for #30

tim.plunkett’s picture

  1. +++ b/core/modules/layout_builder/src/Form/OverridesEntityForm.php
    @@ -88,6 +89,14 @@ protected function init(FormStateInterface $form_state) {
    +    if ($entity_type instanceof ContentEntityTypeInterface && $entity_type->showRevisionUi()) {
    

    This form extends ContentEntityForm, so the instanceof check isn't needed and there's a $this->showRevisionUi() method already that can be used.

  2. +++ b/core/modules/layout_builder/src/Form/OverridesEntityForm.php
    @@ -88,6 +89,14 @@ protected function init(FormStateInterface $form_state) {
    +      $revision_log_message_form_item = $entity_type->getRevisionMetadataKey('revision_log_message');
    +      $log_field_definition = $this->entity->getFieldDefinition($revision_log_message_form_item);
    +      $log_field_revision_message_form_data = $log_field_definition->getDisplayOptions('form');
    +      $form_display->setComponent($revision_log_message_form_item, $log_field_revision_message_form_data);
    

    I guess my real question is: why do we need this when I don't see any other part of core doing it?

    The only time I see revision_log_message related to form displays is for things like Term where it's being hidden. Which implies that the default is to have this shown. So is there some other place we're doing something wrong instead?

    In fact, there are only two places in core that $form_display->setComponent() is ever called: a form alter (which makes sense), and here. That makes me feel like we're missing something

  3. +++ b/core/modules/layout_builder/tests/src/Functional/LayoutBuilderRevisionTest.php
    @@ -0,0 +1,108 @@
    +  public static $modules = [
    

    protected not public

  4. +++ b/core/modules/layout_builder/tests/src/Functional/LayoutBuilderRevisionTest.php
    @@ -0,0 +1,108 @@
    +    $components = Node::load(1)->get('layout_builder__layout')->getSection(0)->getComponents();
    

    I bet this is copied from somewhere else, so no one's fault here. But this should use the OverridesSectionStorage:: constant instead of 'layout_builder__layout'

joegraduate’s picture

Issue summary: View changes
Status: Needs work » Needs review
Issue tags: -Needs issue summary update
Related issues: +#3038442: Use hook_entity_form_display_alter() instead of Layout Builder's custom overrides display altering hook
StatusFileSize
new4.64 KB
new2.5 KB

Addressed items 1, 3 & 4 from #36.

@tim.plunkett Re: item 2 in #36, I definitely don't know the answer to your question(s) but the only alternative to this implementation that I can think of would be to change the $default_fallback parameter to TRUE in the call to EntityFormDisplay::collectRenderDisplay() and I imagine that would cause other problems.

FWIW, it seems that this issue was introduced as a result of the changes committed for #3038442: Use hook_entity_form_display_alter() instead of Layout Builder's custom overrides display altering hook (based on earlier comments #4 and #7 in this issue).

mitthukumawat’s picture

Patch applied successfully for me on drupal 9.3.x-dev version. Thanks for the patch. RTBC +1

joegraduate’s picture

Created MR from #37 to make Tugboat QA site available.

joegraduate’s picture

Title: Revision UI on Layout Builder does not function correctly » Revision log message field missing from layout overrides entity form
Issue summary: View changes

Updated issue title and issue summary because this part of the original issue report is not reproducible in 9.3.x:

When saving a layout override for an entity, a new entity revision is created regardless of whether the "Create new revision" checkbox is checked or not.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

dcam’s picture

My content supervisors are asking for this functionality, so I tested the patch on our dev site. It worked. The revision message field is now visible and usable on the Layout Builder page. I'll see if I can find time to do a proper patch review later.

luke.leber’s picture

Status: Needs review » Reviewed & tested by the community

I think that this can be safely moved to RTBC without addressing #36.2. The solution seems to work great and there is test coverage.

My rationality here is that imperfect under-the-hood implementation is preferable to broken functionality. In situations like this, IMO it is preferable to restore functionality and then open a task to address any concerns in the working functionality.

quietone’s picture

Status: Reviewed & tested by the community » Needs work

The MR is on 9.3.x. Let's get a patch for 9.5 and 10.

ravi.shankar’s picture

Status: Needs work » Needs review
StatusFileSize
new4.64 KB

Added a patch for Drupal 9.5.x which is also getting applied on Drupal 10.1.x

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Issue summary: View changes
Status: Needs review » Needs work
Issue tags: +Needs Review Queue Initiative

This issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request as a guide.

Moving to NW for an answer for 36.2

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

uniquename’s picture

The patch from #48 seems to create a corrupted revision, when saving the layout form without any changes.

Steps to reproduce:

1. Get a fresh installed d10.1.5 with layout builder enabled and the patch applied.
2. Have a content type that has the full view enabled for layout builder.
3. Create a node of that content type.
4. This will create the first revision on /node/1/revisions.
5. Goto /node/1/layout and press save layout without changing anything.
6. No new revision will show up on /node/1/revisions.
7. Goto /node/1/layout, move a block an press save layout.
8. A new revision will show up on /node/1/revisions, but hast vid 3.

I've also found that in the DB in node_field_revision are three entries, so 5. created data, but this row has the revision_translation_affected field emtpy. That's why it's not showing up on /node/1/revisions.

Edit: Sorry, just realized that even without the patch, a corrupted revision get's saved. So is is probably another bug.

firewaller’s picture

Patch #48 resolves the issue for us

matthiasm11’s picture

Status: Needs work » Needs review
needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new2.33 KB

The Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

jastraat made their first commit to this issue’s fork.

bkosborne made their first commit to this issue’s fork.

bkosborne’s picture

Status: Needs work » Reviewed & tested by the community

This looks good to me. I merged in the latest from 11.x and fixed a couple minor deprecation issues in the test.

catch’s picture

Version: 11.x-dev » 11.3.x-dev
Status: Reviewed & tested by the community » Fixed

Committed/pushed to 11.x and cherry-picked to 11.3.x, thanks!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • catch committed d2c03d8f on 11.3.x
    fix: #3033516 Revision log message field missing from layout overrides...

  • catch committed c12cc19d on 11.x
    fix: #3033516 Revision log message field missing from layout overrides...

Status: Fixed » Closed (fixed)

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