Created
January 30, 2024 20:21
-
-
Save welly/195d9d703707c61b09661220c745fd98 to your computer and use it in GitHub Desktop.
Passing attributes between theme hooks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function some_theme_preprocess_paragraph(&$variables) { | |
$element = &$variables['elements']; | |
$paragraph = $variables['paragraph']; | |
if ($paragraph->getType() === 'image_gallery') { | |
$images = $paragraph->get('field_image_gallery'); | |
foreach ($images->referencedEntities() as $image) { | |
$image->parent_paragraph = $paragraph; | |
} | |
} | |
} | |
function some_theme_theme_suggestions_media_alter(array &$suggestions, array $variables) { | |
$media = $variables['elements']['#media']; | |
if ($paragraph = $media->parent_paragraph) { | |
$suggestions[] = $variables['theme_hook_original'] . '__' . $media->bundle() . '__' . $paragraph->getType(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment