Skip to content

Instantly share code, notes, and snippets.

@NikLP

NikLP/theme.theme

Created May 5, 2017
Embed
What would you like to do?
Sacrilegious's way to get forms in templates for D8
/**
* Provides suggestions for different parts, so that blocks are properly loaded
*
* @see hook_theme_suggestions_alter()
*
* @param array $suggestions
* @param array $variables
* @param string $hook
*/
function hook_theme_suggestions_alter(array &$suggestions, array $variables, $hook) {
switch ($hook) {
case 'form':
if (isset($variables['element']['#form_id'])) {
$suggestions[] = $hook . '__' . $variables['element']['#form_id'];
}
break;
}
}
/**
* @implements template_preprocess_HOOK()
*
* @param array $variables
*/
function hook_preprocess_form(&$variables) {
if (isset($variables['element'])) {
foreach (\Drupal\Core\Render\Element::children($variables['element']) as $key) {
$variables['form'][$key] = $variables['element'][$key];
unset($variables['form'][$key]['#markup']);
$variables['form'][$key]['#printed'] = FALSE;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.