Problem/Motivation

As a site builder / front end developer, I would like to be able to distinguish layouts displayed on the edit UI from layouts rendered normally.
This would be especially useful if a layout does not display empty regions: if it does so, then on the edit U, it makes impossible to place any components in the corresponding region.

Core change record: https://www.drupal.org/node/3273879

Proposed resolution

Utilize layout preview mode: use PreviewAwarePluginInterface::setInPreview() to mark layouts as being in preview on Layout Paragraphs edit UI.

User interface changes

Nothing.

API changes

Layouts rendered in Layout Paragraphs edit UI are marked as "being in preview", just like on Layout Builder UI, so the in_preview/code> twig variable could be used in layout templates to distinguish preview / non-preview states.

Data model changes

Nothing.

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

huzooka created an issue. See original summary.

huzooka’s picture

Status: Active » Needs review
StatusFileSize
new3.58 KB

Seems that Gitlab CI is out of office hours...

huzooka’s picture

huzooka’s picture

Assigned: huzooka » Unassigned
StatusFileSize
new824 bytes

Attaching fix-only patch.

hudri’s picture

@huzooka:

Could this setting be used to determine the _admin_route context from routes?

Currently, when LP performs Ajax callbacks, we don't know if we are in admin mode or not. Could this Plugin be used to solve issues 3350168 (which currently is stuck, because it is a node-only solution).

gregory_visible’s picture

This issue is quite old , but not setting preview mode also prevent layouts generated from SDC by Ui_patterns to work correctly.

See : https://www.drupal.org/project/ui_patterns/issues/3578831

anybody’s picture

Version: 2.0.x-dev » 2.1.x-dev
Category: Feature request » Bug report
Priority: Minor » Normal
Related issues: +#3578831: Layout Paragraph Compatibility

Thank you all!

Based on #7 I think we should then rate this as bug. And I think it should be checked, if the same issue exists in 3.x so it can be fixed in both branches?

anybody’s picture

Issue summary: View changes
anybody’s picture

Title: Utilize layout preview mode » in_preview not passed correctly causing wrong display in edit

Relabelled based on #7. The same issue exists in 3.0.x.

@huzooka could you maybe add the same fix for 3.0.x-dev and check why tests fail?

anybody’s picture

Priority: Normal » Major

This became a major issue for us now, because the preview plus view mode not being passed correctly leads to an infinite loop of rendering indirectly. The MR!139 fixes it, thank you @huzooka!

PS: I think the existing MR should target 2.1.x-dev?

anybody’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new3.78 KB

Static patch attached until this is merged.
This works perfectly well with 2.1.x-dev and 3.0.x-dev and also the stable versions!

So I'm setting this RTBC, still we should prepare the MRs to help the maintainers.

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

grevil’s picture

Created two seperate branches for 2.1.x and 3.0.x.

grevil changed the visibility of the branch 3392735-utilize-layout-preview to hidden.

grevil changed the visibility of the branch 2.0.x to hidden.

anybody changed the visibility of the branch 3392735-utilize-layout-preview to active.

grevil changed the visibility of the branch 3392735-utilize-layout-preview to hidden.

grevil’s picture

Failing tests look unrelated. Cypress seems to have issues.

anybody’s picture

Still a major issue for us.

alorenc’s picture

Status: Reviewed & tested by the community » Needs work

The 3.0.x branch no longer uses PHPUnit Functional or FunctionalJavascript tests; browser testing is now done with Cypress (see tests/cypress).

Please migrate the changes in tests/src/FunctionalJavascript/PreprocessLayoutTest.php to a Cypress test for 3.0.x.

alorenc’s picture

grevil’s picture

Version: 2.1.x-dev » 3.0.x-dev
grevil’s picture

Status: Needs work » Needs review

Migrated the test into a cypress test!

anybody’s picture

Status: Needs review » Reviewed & tested by the community

All green, thank you @grevil

alorenc’s picture

That was fast, thanks!

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

minoroffense’s picture

StatusFileSize
new824 bytes

Here's a patch with just the code for 2.1.x

anybody’s picture

Thank you @minoroffense - would be great to have this merged in both versions. :)

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

  • justin2pin committed d2e24356 on 2.1.x authored by grevil
    fix: #3392735 in_preview not passed correctly causing wrong display in...

  • justin2pin committed cd578ad7 on 3.0.x authored by grevil
    fix: #3392735 in_preview not passed correctly causing wrong display in...
justin2pin’s picture

Status: Reviewed & tested by the community » Fixed

Merged and marked as fixed. I added a check to make sure the LayoutInstance also implements PreviewAwarePluginInterface before call setInPreview(), since that isn't a requirement for all layout plugins. Also moved test coverage to unit tests. Thanks for the work on this!

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.

anybody’s picture

Whao, thank you very very much once again @justin2pin! Nice to see this fixed finally!

Status: Fixed » Closed (fixed)

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