diff --git a/core/includes/form.inc b/core/includes/form.inc index dd8060b..ad4cceb 100644 --- a/core/includes/form.inc +++ b/core/includes/form.inc @@ -2686,7 +2686,7 @@ function form_pre_render_color($element) { * @param $variables * An associative array containing: * - element: An associative array containing the properties of the element. - * Properties used: #action, #method, #attributes, #children + * Properties used: #action, #method, #attributes */ function template_preprocess_form(&$variables) { $element = $variables['element']; @@ -2698,7 +2698,7 @@ function template_preprocess_form(&$variables) { $element['#attributes']['accept-charset'] = "UTF-8"; } $variables['attributes'] = $element['#attributes']; - $variables['children'] = $element['#children']; + $variables['form'] = $element; } /** diff --git a/core/lib/Drupal/Core/Form/ConfigFormBase.php b/core/lib/Drupal/Core/Form/ConfigFormBase.php index 8ed7403..4e03df2 100644 --- a/core/lib/Drupal/Core/Form/ConfigFormBase.php +++ b/core/lib/Drupal/Core/Form/ConfigFormBase.php @@ -46,8 +46,9 @@ public function buildForm(array $form, array &$form_state) { '#button_type' => 'primary', ); - // By default, render the form using theme_system_config_form(). - $form['#theme'] = 'system_config_form'; + // By default, render the form using form--system-config.html.twig if + // it exists. + $form['#theme'] = 'form__system_config_form'; return $form; } diff --git a/core/lib/Drupal/Core/Form/FormBuilder.php b/core/lib/Drupal/Core/Form/FormBuilder.php index d3bedc1..f703965 100644 --- a/core/lib/Drupal/Core/Form/FormBuilder.php +++ b/core/lib/Drupal/Core/Form/FormBuilder.php @@ -720,16 +720,26 @@ public function prepareForm($form_id, &$form, &$form_state) { } } - // If no #theme has been set, automatically apply theme suggestions. - // theme_form() itself is in #theme_wrappers and not #theme. Therefore, the - // #theme function only has to care for rendering the inner form elements, - // not the form itself. + // If no #theme has been set, automatically apply theme suggestions for + // form.html.twig. if (!isset($form['#theme'])) { - $form['#theme'] = array($form_id); + $form['#theme'] = array('form__' . $form_id); if (isset($form_state['build_info']['base_form_id'])) { - $form['#theme'][] = $form_state['build_info']['base_form_id']; + $form['#theme'][] = 'form__' . $form_state['build_info']['base_form_id']; } } + elseif(!is_array($form['#theme'])) { + // Start a suggestions array out of the value. + if (strpos($form['#theme'], 'form__') === 0) { + $form['#theme'] = array($form['#theme']); + } + else { + // Prefix the form theme with the suggestion base. + $form['#theme'] = array('form__' . $form['#theme']); + } + } + // Add the default form template to the end. + $form['#theme'][] = 'form'; // Invoke hook_form_alter(), hook_form_BASE_FORM_ID_alter(), and // hook_form_FORM_ID_alter() implementations. diff --git a/core/modules/block/block.module b/core/modules/block/block.module index 4681b8a..73bec91 100644 --- a/core/modules/block/block.module +++ b/core/modules/block/block.module @@ -54,9 +54,9 @@ function block_theme() { 'render element' => 'elements', 'template' => 'block', ), - 'block_list' => array( + 'form__block_list' => array( 'render element' => 'form', - 'template' => 'block-list', + 'template' => 'form--block-list', ), ); } diff --git a/core/modules/block/src/BlockListBuilder.php b/core/modules/block/src/BlockListBuilder.php index 1bf034d..bff76f1 100644 --- a/core/modules/block/src/BlockListBuilder.php +++ b/core/modules/block/src/BlockListBuilder.php @@ -143,7 +143,7 @@ public function buildForm(array $form, array &$form_state) { ); } $entities = $this->load(); - $form['#theme'] = array('block_list'); + $form['#theme'] = array('form__block_list'); $form['#attached']['library'][] = 'core/drupal.tableheader'; $form['#attached']['library'][] = 'block/drupal.block'; $form['#attached']['library'][] = 'block/drupal.block.admin'; diff --git a/core/modules/block/templates/block-list.html.twig b/core/modules/block/templates/block-list.html.twig deleted file mode 100644 index 474c654..0000000 --- a/core/modules/block/templates/block-list.html.twig +++ /dev/null @@ -1,23 +0,0 @@ -{# -/** - * @file - * Two column template for the block add/edit form. - * - * This template will be used when a block edit form specifies 'block_edit_form' - * as its #theme callback. Otherwise, by default, block add/edit forms will be - * themed by theme_form(). - * - * Available variables: - * - form: The block add/edit form. - * - * @ingroup themeable - */ -#} -
-
- {{ form|without('place_blocks') }} -
-
- {{ form.place_blocks }} -
-
diff --git a/core/modules/block/templates/form--block-list.html.twig b/core/modules/block/templates/form--block-list.html.twig new file mode 100644 index 0000000..1cb1696 --- /dev/null +++ b/core/modules/block/templates/form--block-list.html.twig @@ -0,0 +1,26 @@ +{% extends "@system/form.html.twig" %} +{# +/** + * @file + * Two column template for the block add/edit form. + * + * This template will be used when a block edit form specifies 'block_edit_form' + * as its #theme callback. Otherwise, by default, block add/edit forms will be + * themed by theme_form(). + * + * Available variables: + * - form: The block add/edit form. + * + * @ingroup themeable + */ +#} +{% block form %} +
+
+ {{ form|without('place_blocks') }} +
+
+ {{ form.place_blocks }} +
+
+{% endblock %} diff --git a/core/modules/forum/forum.module b/core/modules/forum/forum.module index 0c13945..5fb8de7 100644 --- a/core/modules/forum/forum.module +++ b/core/modules/forum/forum.module @@ -96,9 +96,6 @@ function forum_theme() { 'template' => 'forum-submitted', 'variables' => array('topic' => NULL), ), - 'forum_form' => array( - 'render element' => 'form', - ), ); } @@ -736,19 +733,3 @@ function template_preprocess_forum_submitted(&$variables) { } $variables['time'] = isset($variables['topic']->created) ? format_interval(REQUEST_TIME - $variables['topic']->created) : ''; } - -/** - * Returns HTML for a forum form. - * - * By default this does not alter the appearance of a form at all, but is - * provided as a convenience for themers. - * - * @param $variables - * An associative array containing: - * - form: A render element representing the form. - * - * @ingroup themeable - */ -function theme_forum_form(array $variables) { - return drupal_render_children($variables['form']); -} diff --git a/core/modules/forum/src/Form/ForumForm.php b/core/modules/forum/src/Form/ForumForm.php index 34c64df..f4ff17c 100644 --- a/core/modules/forum/src/Form/ForumForm.php +++ b/core/modules/forum/src/Form/ForumForm.php @@ -53,7 +53,7 @@ public function form(array $form, array &$form_state) { $form['parent']['#tree'] = TRUE; $form['parent'][0] = $this->forumParentSelect($taxonomy_term->id(), $this->t('Parent')); - $form['#theme'] = 'forum_form'; + $form['#theme'] = 'form__forum_form'; $this->forumFormType = $this->t('forum'); return $form; } diff --git a/core/modules/language/language.module b/core/modules/language/language.module index e23d73f..c810d68 100644 --- a/core/modules/language/language.module +++ b/core/modules/language/language.module @@ -105,7 +105,7 @@ function language_permission() { */ function language_theme() { return array( - 'language_negotiation_configure_form' => array( + 'form__language_negotiation_configure_form' => array( 'render element' => 'form', 'file' => 'language.admin.inc', 'template' => 'language-negotiation-configure-form', diff --git a/core/modules/language/src/Form/NegotiationConfigureForm.php b/core/modules/language/src/Form/NegotiationConfigureForm.php index a6d241f..e803c21 100644 --- a/core/modules/language/src/Form/NegotiationConfigureForm.php +++ b/core/modules/language/src/Form/NegotiationConfigureForm.php @@ -97,7 +97,7 @@ public function buildForm(array $form, array &$form_state) { $configurable = $this->languageTypes->get('configurable'); $form = array( - '#theme' => 'language_negotiation_configure_form', + '#theme' => 'form__language_negotiation_configure_form', '#language_types_info' => $this->languageManager->getDefinedLanguageTypesInfo(), '#language_negotiation_info' => $this->negotiator->getNegotiationMethods(), ); diff --git a/core/modules/menu_ui/menu_ui.admin.inc b/core/modules/menu_ui/menu_ui.admin.inc index 0d7a0fd..c4ef9c9 100644 --- a/core/modules/menu_ui/menu_ui.admin.inc +++ b/core/modules/menu_ui/menu_ui.admin.inc @@ -16,7 +16,7 @@ * * @ingroup themeable */ -function theme_menu_overview_form($variables) { +function theme_form__menu_overview_form($variables) { $form = $variables['form']; $header = array( @@ -88,5 +88,8 @@ function theme_menu_overview_form($variables) { $output .= drupal_render($form['inline_actions']); $output .= drupal_render($table); $output .= drupal_render_children($form); + + // Temporary pass through to form.html.twig until template conversion. + $output = _theme('form', $variables = array('form' => $output)); return $output; } diff --git a/core/modules/menu_ui/menu_ui.module b/core/modules/menu_ui/menu_ui.module index 5e2f5bc..fed76f7 100644 --- a/core/modules/menu_ui/menu_ui.module +++ b/core/modules/menu_ui/menu_ui.module @@ -106,7 +106,7 @@ function menu_ui_entity_bundle_info() { */ function menu_ui_theme() { return array( - 'menu_overview_form' => array( + 'form__menu_overview_form' => array( 'file' => 'menu_ui.admin.inc', 'render element' => 'form', ), diff --git a/core/modules/menu_ui/src/MenuForm.php b/core/modules/menu_ui/src/MenuForm.php index d854f3c..f57cea3 100644 --- a/core/modules/menu_ui/src/MenuForm.php +++ b/core/modules/menu_ui/src/MenuForm.php @@ -248,7 +248,7 @@ protected function buildOverviewForm(array &$form, array &$form_state) { // Ensure that menu_overview_form_submit() knows the parents of this form // section. $form['#tree'] = TRUE; - $form['#theme'] = 'menu_overview_form'; + $form['#theme'] = 'form__menu_overview_form'; $form_state += array('menu_overview_form_parents' => array()); $form['#attached']['css'] = array(drupal_get_path('module', 'menu') . '/css/menu.admin.css'); diff --git a/core/modules/system/system.module b/core/modules/system/system.module index 3d67b65..1be3de4 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -177,7 +177,7 @@ function system_theme() { 'file' => 'system.admin.inc', 'template' => 'system-themes-page', ), - 'system_config_form' => array( + 'form__system_config_form' => array( 'render element' => 'form', 'template' => 'system-config-form', ), @@ -296,7 +296,7 @@ function system_element_info() { $types['form'] = array( '#method' => 'post', '#action' => request_uri(), - '#theme_wrappers' => array('form'), + '#theme' => array('form'), ); $types['page'] = array( '#show_messages' => TRUE, diff --git a/core/modules/system/templates/confirm-form.html.twig b/core/modules/system/templates/confirm-form.html.twig deleted file mode 100644 index d714917..0000000 --- a/core/modules/system/templates/confirm-form.html.twig +++ /dev/null @@ -1,15 +0,0 @@ -{# -/** - * @file - * Default theme implementation for confirm form. - * - * By default this does not alter the appearance of a form at all, - * but is provided as a convenience for themers. - * - * Available variables: - * - form: The confirm form. - * - * @ingroup themeable - */ -#} -{{ form }} diff --git a/core/modules/system/templates/form.html.twig b/core/modules/system/templates/form.html.twig index 2cd1e95..cfe1dbc 100644 --- a/core/modules/system/templates/form.html.twig +++ b/core/modules/system/templates/form.html.twig @@ -5,7 +5,7 @@ * * Available variables * - attributes: A list of HTML attributes for the wrapper element. - * - children: The child elements of the form. + * - form: The child elements of the form. * * @see template_preprocess_form() * @@ -13,5 +13,7 @@ */ #} - {{ children }} + {% block form %} + {{ form }} + {% endblock %} diff --git a/core/modules/update/update.manager.inc b/core/modules/update/update.manager.inc index 86872da..4582376 100644 --- a/core/modules/update/update.manager.inc +++ b/core/modules/update/update.manager.inc @@ -72,7 +72,7 @@ function update_manager_update_form($form, $form_state = array(), $context) { return $form; } - $form['#theme'] = 'update_manager_update_form'; + $form['#theme'] = 'form__update_manager_update_form'; $available = update_get_available(TRUE); if (empty($available)) { @@ -287,7 +287,7 @@ function update_manager_update_form($form, $form_state = array(), $context) { * * @ingroup themeable */ -function theme_update_manager_update_form($variables) { +function theme_form__update_manager_update_form($variables) { $form = $variables['form']; $last = \Drupal::state()->get('update.last_check') ?: 0; $update_last_check = array( @@ -296,6 +296,9 @@ function theme_update_manager_update_form($variables) { ); $output = drupal_render($update_last_check); $output .= drupal_render_children($form); + + // Temporary pass through to form.html.twig until template conversion. + $output = _theme('form', $variables = array('form' => $output)); return $output; } diff --git a/core/modules/update/update.module b/core/modules/update/update.module index 243eae9..2efb57d 100644 --- a/core/modules/update/update.module +++ b/core/modules/update/update.module @@ -172,7 +172,7 @@ function update_manager_access() { */ function update_theme() { return array( - 'update_manager_update_form' => array( + 'form__update_manager_update_form' => array( 'render element' => 'form', 'file' => 'update.manager.inc', ), diff --git a/core/modules/views/src/Plugin/views/filter/FilterPluginBase.php b/core/modules/views/src/Plugin/views/filter/FilterPluginBase.php index 30d702d..e780bab 100644 --- a/core/modules/views/src/Plugin/views/filter/FilterPluginBase.php +++ b/core/modules/views/src/Plugin/views/filter/FilterPluginBase.php @@ -499,7 +499,7 @@ public function showExposeButton(&$form, &$form_state) { * @see buildOptionsForm() */ public function buildExposeForm(&$form, &$form_state) { - $form['#theme'] = 'views_ui_expose_filter_form'; + $form['#theme'] = 'form__views_ui_expose_filter_form'; // #flatten will move everything from $form['expose'][$key] to $form[$key] // prior to rendering. That's why the preRender for it needs to run first, // so that when the next preRender (the one for fieldsets) runs, it gets diff --git a/core/modules/views_ui/templates/form--views-ui-expose-filter-form.html.twig b/core/modules/views_ui/templates/form--views-ui-expose-filter-form.html.twig new file mode 100644 index 0000000..ce697fb --- /dev/null +++ b/core/modules/views_ui/templates/form--views-ui-expose-filter-form.html.twig @@ -0,0 +1,64 @@ +{% extends "@system/form.html.twig" %} +{# +/** + * @file + * Default theme implementation for a 'form' element. + * + * Available variables + * - attributes: A list of HTML attributes for the wrapper element. + * - children: The child elements of the form. + * + * @see template_preprocess_form() + * + * @ingroup themeable + */ +#} +{% block form %} + + {% + set extracted = [ + 'form_description', + 'expose_button', + 'group_button', + 'required', + 'label', + 'description', + 'operator', + 'value', + 'use_operator', + 'more', + ] + %} + + {{ form.form_description }} + + {{ form.expose_button }} + {{ form.group_button }} + {% if form.required %} + {{ form.required }} + {% endif %} + + {{ form.label }} + {{ form.description }} + + {{ form.operator }} + {{ form.value }} + + {% if form.use_operator %} +
+ {{ form.use_operator }} +
+ {% endif %} + + {# Only output the right column markup if there's a left column to begin with #} + {% if form.operator['#type'] is not empty %} +
+ {{ form|without(extracted) }} +
+ {% else %} + {{ form|without(extracted) }} + {% endif %} + + {{ form.more }} + +{% endblock %} diff --git a/core/modules/views_ui/views_ui.module b/core/modules/views_ui/views_ui.module index 9e0d08d..19ea8a7 100644 --- a/core/modules/views_ui/views_ui.module +++ b/core/modules/views_ui/views_ui.module @@ -77,13 +77,14 @@ function views_ui_theme() { 'template' => 'views-ui-display-tab-bucket', 'file' => 'views_ui.theme.inc', ), - 'views_ui_rearrange_filter_form' => array( + 'form__views_ui_rearrange_filter_form' => array( 'render element' => 'form', 'file' => 'views_ui.theme.inc', ), - 'views_ui_expose_filter_form' => array( + 'form__views_ui_expose_filter_form' => array( 'render element' => 'form', 'file' => 'views_ui.theme.inc', + 'template' => 'form--views-ui-expose-filter-form', ), // list views @@ -94,7 +95,7 @@ function views_ui_theme() { ), // Group of filters. - 'views_ui_build_group_filter_form' => array( + 'form__views_ui_build_group_filter_form' => array( 'render element' => 'form', 'file' => 'views_ui.theme.inc', ), diff --git a/core/modules/views_ui/views_ui.theme.inc b/core/modules/views_ui/views_ui.theme.inc index 430f14a..f977ade 100644 --- a/core/modules/views_ui/views_ui.theme.inc +++ b/core/modules/views_ui/views_ui.theme.inc @@ -92,49 +92,9 @@ function template_preprocess_views_ui_view_info(&$variables) { } /** - * Theme the expose filter form. - */ -function theme_views_ui_expose_filter_form($variables) { - $form = $variables['form']; - $more = drupal_render($form['more']); - - $output = drupal_render($form['form_description']); - $output .= drupal_render($form['expose_button']); - $output .= drupal_render($form['group_button']); - if (isset($form['required'])) { - $output .= drupal_render($form['required']); - } - $output .= drupal_render($form['label']); - $output .= drupal_render($form['description']); - - $output .= drupal_render($form['operator']); - $output .= drupal_render($form['value']); - - if (isset($form['use_operator'])) { - $output .= '
'; - $output .= drupal_render($form['use_operator']); - $output .= '
'; - } - - // Only output the right column markup if there's a left column to begin with - if (!empty($form['operator']['#type'])) { - $output .= '
'; - $output .= drupal_render_children($form); - $output .= '
'; - } - else { - $output .= drupal_render_children($form); - } - - $output .= $more; - - return $output; -} - -/** * Theme the build group filter form. */ -function theme_views_ui_build_group_filter_form($variables) { +function theme_form__views_ui_build_group_filter_form($variables) { $form = $variables['form']; $more = drupal_render($form['more']); @@ -212,13 +172,17 @@ function theme_views_ui_build_group_filter_form($variables) { ), ); $render_form = drupal_render_children($form); - return $output . $render_form . drupal_render($table) . drupal_render($form['add_group']) . $more; + $output = $output . $render_form . drupal_render($table) . drupal_render($form['add_group']) . $more; + + // Temporary pass through to form.html.twig until template conversion. + $output = _theme('form', $variables = array('form' => $output)); + return $output; } /** * Turn the rearrange form into a proper table */ -function theme_views_ui_rearrange_filter_form(&$variables) { +function theme_form__views_ui_rearrange_filter_form(&$variables) { $form = $variables['form']; $rows = $ungroupable_rows = array(); // Enable grouping only if > 1 group. @@ -341,6 +305,9 @@ function theme_views_ui_rearrange_filter_form(&$variables) { // Render the rest of the form and return. $output .= drupal_render_children($form); + + // Temporary pass through to form.html.twig until template conversion. + $output = _theme('form', $variables = array('form' => $output)); return $output; }