Issue with node previews

Created on 9 July 2025, 3 days ago

Problem/Motivation

This seems to be an issue with how this module interacts with the frontend editing module, but it's unclear what the interaction should be. Since you're a maintainer on both I thought I'd start here. The problem is that it's very easy to break node automatic preview with how it works currently. Both this module and the frontend editing module have checks like this in the code, so that any entity needs to be enabled before it'll work for preview :

    // Check if preview is allowed.
    $preview_config = \Drupal::config('preview.settings')->get('enabled') ?? [];
    if (!empty($preview_config[$entity->getEntityTypeId()][$entity->bundle()])) {
      //Do a thing
    }

However the settings form for the automated preview module has this code in the loop that builds out the available entities to be controlled.

        // We already have that for nodes.
        if ($entity_type_id === 'node') {
          continue;
        }

The frontend editing module enables all the entities selected on its settings when this module is turned on, which adds the nodes to the settings for the preview module. But because it doesn't render that on its own settings screen, if you make changes on this page for any reason the nodes part of the settings is wiped out and breaks any automatic preview for node pages.

Steps to reproduce

  1. Enable the frontend editing module.
  2. Enable various content types to support front-end editing.
  3. Enable the preview module. At this point, automated preview should be working correctly
  4. Go to /admin/config/content/preview and change any settings there
  5. At this point automated preview will stop working

Proposed resolution

I think there's two pieces to this. The first is, how should this be working? Hiding it in the settings screen implies that by default all nodes should support this, but that's not how it works currently. Should the fix be to expose that information on the settings screen to prevent it from being wiped out or updating the module(s) so that they can work without the nodes being in the settings screen?

The second is that I think the UI needs to reflect better the state of automated preview. There's no indication currently when preview module isn't properly configured for a content item.

Remaining tasks

Determine the correct way the module should be working.
Bubble up helpful information to the user screens if settings aren't correct to allow automated preview to work.

User interface changes

I think the "automated preview" toggle in the frontend editing window should be greyed out when that content isn't enabled to support that, to give an indication to the user why it's not working.

API changes

Not directly connected to this, but I think we also need a service to handle the checks for determining when an entity is enabled for preview.

I.e., downstream modules should be able to check like this so that we can make future updates around this logic without having to worry about breaking downstream modules.

    // Check if preview is allowed.
    if (\Drupal::service("preview.someservice")->isPreviewAllowed($entity->getEntityTypeId(), $entity->bundle())) {
      //Do a thing
    }
πŸ› Bug report
Status

Active

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States jacobbell84

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @jacobbell84
  • πŸ‡©πŸ‡ͺGermany a.dmitriiev

    The all_entity_preview module (or just preview as machine name states) is not taking care of node entity type preview. It handles all other content entity types, BUT node, because node module already has a preview functionality. That is why the configuration for node is skipped in the settings form and that is why there are some checks in the frontend editing module.

    Nodes have their own settings to enable/disable the preview and frontend editing respects those settings. To be more clear, the "Preview" button on node form is added by node module and if it is present, then frontend editing tries to process further. Actually the same is for other entity types, but for them "All Entity Preview" module adds that "Preview" button to the form.

    It seems that function frontend_editing_enable_preview accidentally adds node entity type to the preview module settings, because in your case the node entity type is allowed to be used by frontend editing. That is definitely a bug and needs to be fixed. Thank you for noticing.

    To fix your problem with node preview try to enable it for a content type. You can do this on content type edit page, for example here /admin/structure/types/manage/page for content type "Page":

    "Preview before submitting" should not be "Disabled".

    Please let me know if it helps and for the function frontend_editing_enable_preview, I will fix it in the frontend_editing module.

Production build 0.71.5 2024