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
- Enable the frontend editing module.
- Enable various content types to support front-end editing.
- Enable the preview module. At this point, automated preview should be working correctly
- Go to /admin/config/content/preview and change any settings there
- 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
}