- 🇦🇷Argentina darktek
Thanks @hudri the #3 💬 How to getParentEntity() in node preview mode? Active saved my life :)
I'm doing quite a lot of preprocessing in my theme, and I noticed that sometimes my preprocessing does not work in node preview mode. I've got quite a lot of code similar to
function MYTHEME_preprocess_paragraph__TYPE(array &$variables) {
$paragraph = $variables['paragraph'];
$parent = $paragraph->getParentEntity();
if ($parent && $parent->whateverCondition()) {
...
}
}
I noticed that in node preview mode getParentEntity()
is often (but not always) null. It seems that getParentEntity()
does work in case of nested paragraphs, but does not work if the paragraph is direct descendant of a node.
I guess it is related to the missing node id for preview nodes (they only seem to have an UUID), but I don't know how to work around this limitation.
Can anyone give me some hints how to reliably fetch the parent entity? (must work for nodes and nested paragraphs, and must also work in node preview mode)
Active
1.3
Code
Not all content is available!
It's likely this issue predates Contrib.social: some issue and comment data are missing.
Thanks @hudri the #3 💬 How to getParentEntity() in node preview mode? Active saved my life :)