I’m struggling with the php syntax to create a theme suggestion for form elements that uses both the field ID and the node ID.
I’m trying to achieve this theme suggestion: form-element--first-name--23.html.twig
Here’s the function I’m playing with, based on some info from this article.
function mytheme_theme_suggestions_form_element_alter(array &$suggestions, array $variables, $hook) { $object = $variables['element']['#object']; $id = str_replace("-", "_", $variables['element']['#id']); if (get_class($object) == 'DrupalnodeEntityNode') { $suggestions[] = $hook . '__' . $id . '__' . $node->id(); } }