Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $renderer = Drupal::service('renderer');
- $renderer->addCacheableDependency($variables, $referring_entity);
- function hook_preprocess_paragraph(&$variables) {
- foreach (Element::children($variables['content']['field_your_field']) as $index) {
- $child = &$variables['content']['field_your_field'][$index];
- if (your view switching logic) {
- $child['#view_mode'] = 'your_new_view_mode';
- // Update cache keys
- array_pop($child['#cache']['keys']);
- $child['#cache']['keys'][] = $child['#view_mode'];
- }
- }
- }
Add Comment
Please, Sign In to add comment