Problem/Motivation

ds_switch_view_mode.module hardcodes a reference to Drupal\content_moderation\ContentPreprocess

That class was removed from Drupal core in #2877924: Remove ContentPreprocess and associated code, landing in core 11.4. On any site running content_moderation + core ≥ 11.4, rendering a node that has a ds_switch value set now throws:
InvalidArgumentException: Class "Drupal\content_moderation\ContentPreprocess" does not exist.

This is a hard fatal (500), not a degraded fallback — it breaks rendering entirely for any node using DS's "switch view mode" feature once content_moderation is enabled.

The core removal itself was downstream of #3458589: Deprecate $variables['page'] for node.html.twig and node_is_page(), whose rationale is that node_is_page()/'page' are redundant with checking view_mode == 'full' directly. The eventual "real" replacement service is being tracked in #3515218: [Regression] Restore functionality of node_is_page, generalised to content entity types, which is still active/unresolved as of this writing — so there's no drop-in replacement class to swap to yet.

Steps to reproduce

  1. Enable content_moderation and ds_switch_view_mode.
  2. Set a ds_switch value on any node.
  3. View that node (or anything that triggers hook_entity_view_mode_alter() for it, e.g. Mercury Editor's preview route) on Drupal core ≥ 11.4.
  4. Observe a fatal error instead of the page rendering.

Proposed resolution

Drop the node_is_page()/ContentPreprocess fallback block entirely. Per core's own rationale in #3458589, the outer $view_mode == 'full' check already covers what this inner check was testing for, so the block may simply be redundant now:

function ds_switch_view_mode_entity_view_mode_alter(&$view_mode, EntityInterface $entity, $context) {
  if ($entity->getEntityTypeId() == 'node' && !empty($entity->ds_switch->value) && $view_mode == 'full') {
    $view_mode = $entity->ds_switch->value;
    \Drupal::moduleHandler()->alter('ds_switch_view_mode', $view_mode, $original_view_mode, $entity);
  }
}

Remaining tasks

User interface changes

API changes

Data model changes

Issue fork ds-3618575

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

msypes created an issue. See original summary.

msypes’s picture

StatusFileSize
new1.18 KB