I am using Drupal 8 and would like to customize how form elements are being displayed. Specifically, I don't like how uneditable, populated textfields are displayed as plain text. I would have it being displayed as an editable textfield (or have the text look like it is in an uneditable textfield). I have looked at various hook functions to try and achieve this but nothing seems to work.
I figure the best way to go about this is if I can render the form fields individually myself and then create a twig file that displays the individual fields as I would like them to be displayed. Here is what I would like the twig field to look like:
<div class="from">
{{ form.mail }}
</div>
<div class="message">
{{ form.message }}
</div>
<div class="actions">
{{ form.actions }}
</div>
This is what I came up with so far:
function theme_preprocess_form(&$variables) {
$elements = $variables['element'];
foreach($elements as $key => $element) {
if (substr( $key, 0, 1 ) !== "#" ) {
// $variables['form'][$key] = render[$element];
// This is where I need the code to actually render the element
}
}
}
What is the function I need to call to return a fully rendered form element?
To clarify, I would like to accomplish this by only using they my_theme.theme file for my_theme.
Thanks.