Issue #2152221 by steveoliver, joelpittet, hussainweb, shanethehat, jenlampton, kpa, AnythonyR, EVIIILJ, kgoel, Cottser, dsdeiz, hanpersand: Convert theme_radios() to Twig

Task

Convert theme_radios() to a Twig template.

Remaining tasks

  • Patch
  • Patch review
  • Manual testing
  • Profiling

Steps to test

@todo

Comments

Cottser’s picture

Issue summary: View changes

Adding a commit message to the issue summary so the folks who already worked on #1898480: [meta] form.inc - Convert theme_ functions to Twig and in the Twig sandbox get credit.

rteijeiro’s picture

Assigned: Unassigned » rteijeiro

Working on this one...

rteijeiro’s picture

Status: Active » Needs review
FileSize
2.93 KB
PASSED: [[SimpleTest]]: [MySQL] 63,062 pass(es). View

Let's see...

rteijeiro’s picture

Assigned: rteijeiro » Unassigned
michamilz’s picture

sheilaj’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
36.61 KB
75.94 KB
20.47 KB
51.56 KB

Tested on a two field instances (list and boolean). The markup before and after applying the patch (in #3) was identical. See attached screenshots, with twig debug code in the 'after' shots.

Cottser’s picture

Status: Reviewed & tested by the community » Needs review
Issue tags: -Needs manual testing

Thanks @sheilaj! I think that means we can remove the "Needs manual testing" tag, but this patch does still need profiling.

burgerboydaddy’s picture

Scenario for profiling
1. login as admin
2. select structure; contact form categories
3. select website feedback, click edit
4. go to manage fields
5. add new field
label: some check boxes
field type: list (integer)
6. click on save
7. enter that user must select at least 2 options
list of options:
10|check me 10
11|check me 11
12|check me 12
13|check me 13
14|check me 14
8. Save; go to manage display. select "checkboxes/radio" for display
9. now add another field
label: some radio buttons
field type: list (integer)
10. click on save
11. enter that user must select just 1 option
list of options:
1|check me 1
2|check me 2
3|check me 3
4|check me 4
5|check me 5
12. Save; go to manage display. select "checkboxes/radio" for display
13. go to system settings and enter as default page: /contact
14. now open site, contact form with checkboxes and radio buttons will be displayed.
15. now is good moment to backup database since it can be used again later for radio buttons

<!-- THEME DEBUG -->
<!-- CALL: theme('radios') -->
<!-- BEGIN OUTPUT from 'core/modules/system/templates/radios.html.twig' -->
<div aria-describedby="edit-field-some-radio-buttons--description" id="edit-field-some-radio-buttons" class="form-radios"><div class="form-item form-type-radio form-item-field-some-radio-buttons">
 <input aria-describedby="edit-field-some-radio-buttons--description" type="radio" id="edit-field-some-radio-buttons-1" name="field_some_radio_buttons" value="1" class="form-radio" /> <label class="option" for="edit-field-some-radio-buttons-1">option 1</label>
</div>
<div class="form-item form-type-radio form-item-field-some-radio-buttons">
 <input aria-describedby="edit-field-some-radio-buttons--description" type="radio" id="edit-field-some-radio-buttons-2" name="field_some_radio_buttons" value="2" class="form-radio" /> <label class="option" for="edit-field-some-radio-buttons-2">option 2</label>
</div>
<div class="form-item form-type-radio form-item-field-some-radio-buttons">
 <input aria-describedby="edit-field-some-radio-buttons--description" type="radio" id="edit-field-some-radio-buttons-3" name="field_some_radio_buttons" value="3" class="form-radio" /> <label class="option" for="edit-field-some-radio-buttons-3">option 3</label>
</div>
<div class="form-item form-type-radio form-item-field-some-radio-buttons">
 <input aria-describedby="edit-field-some-radio-buttons--description" type="radio" id="edit-field-some-radio-buttons-4" name="field_some_radio_buttons" value="4" class="form-radio" /> <label class="option" for="edit-field-some-radio-buttons-4">option 4</label>
</div>
</div>

<!-- END OUTPUT from 'core/modules/system/templates/radios.html.twig' -->

Profiling test results:
Run 52e4a1c03557c uploaded successfully for drupal-perf-drupalcon.
Run 52e4a1fd8a982 uploaded successfully for drupal-perf-drupalcon.

=== 8.x..8.x compared (52e4a1c03557c..52e4a1fd8a982):

ct  : 38,893|38,893|0|0.0%
wt  : 159,364|158,964|-400|-0.3%
cpu : 148,493|148,120|-373|-0.3%
mu  : 14,562,696|14,562,696|0|0.0%
pmu : 14,669,600|14,669,600|0|0.0%

http://www.lionsad.de/xhprof-kit/xhprof/xhprof_html/?run1=52e4a1c03557c&...

Run 52e4a1c03557c uploaded successfully for drupal-perf-drupalcon.
Run 52e4a222581ef uploaded successfully for drupal-perf-drupalcon.

=== 8.x..2152221-3-radio-twig compared (52e4a1c03557c..52e4a222581ef):

ct  : 38,893|38,984|91|0.2%
wt  : 159,364|159,857|493|0.3%
cpu : 148,493|148,705|212|0.1%
mu  : 14,562,696|14,588,408|25,712|0.2%
pmu : 14,669,600|14,696,032|26,432|0.2%

http://www.lionsad.de/xhprof-kit/xhprof/xhprof_html/?run1=52e4a1c03557c&...

burgerboydaddy’s picture

Issue tags: -Needs profiling
InternetDevels’s picture

FileSize
2.22 KB
FAILED: [[SimpleTest]]: [MySQL] Drupal installation failed. View
1.25 KB

Fixed comments standards.

Status: Needs review » Needs work

The last submitted patch, 10: convert-theme-radios-2152221-10_1.patch, failed testing.

Cottser’s picture

Issue tags: +Twig conversion
joelpittet’s picture

+++ b/core/includes/form.inc
@@ -1071,7 +1071,7 @@
+  $variables['children'] = isset($element['#children']) ? $element['#children'] : '';

isset() is not nessasary, i't always initialized in drupal_render()

And the reason it's failing is because the twig template was dropped in patch #10

Cottser’s picture

Issue tags: +Novice

Tagging as a novice task to add back the lost Twig template and make the change mentioned in #13.

IshaDakota’s picture

Status: Needs work » Needs review
FileSize
2.93 KB
PASSED: [[SimpleTest]]: [MySQL] 64,364 pass(es). View
706 bytes
  1. Re-added the dropped template and rolled back the change identified in comment 13.
  2. Removed extra line in comment for function form_pre_render_radio().
  3. Created interdiff from patch in comment 3.
joelpittet’s picture

Could you tackle this change too?
+ $variables['children'] = isset($element['#children']) ? $element['#children'] : '';
to
+ $variables['children'] = $element['#children'];

IshaDakota’s picture

FileSize
2.9 KB
PASSED: [[SimpleTest]]: [MySQL] 64,306 pass(es). View
510 bytes

Of course!

Sorry, misunderstood the comment before.

joelpittet’s picture

  1. +++ b/core/includes/form.inc
    @@ -1037,30 +1037,33 @@ function form_pre_render_radio($element) {
    -  $attributes = array();
    ...
    +  // Remove the disabled attibute on the wrapper.
    +  unset($variables['attributes']['disabled']);
    

    Just a note, these two lines are doing essentially the same thing.

  2. +++ b/core/includes/form.inc
    @@ -1037,30 +1037,33 @@ function form_pre_render_radio($element) {
    +  $variables['attributes']['class'] = array();
    

    This line is clobbering any css class that gets passed through

  3. +++ b/core/includes/form.inc
    @@ -1037,30 +1037,33 @@ function form_pre_render_radio($element) {
    +  $variables['attributes']['class'][] = 'form-radios';
       if (!empty($element['#attributes']['class'])) {
    -    $attributes['class'] .= ' ' . implode(' ', $element['#attributes']['class']);
    +    $variables['attributes']['class'] = array_merge($variables['attributes']['class'], $element['#attributes']['class']);
       }
    

    So saying that, we might as well remove the array_merge, which is a heavy function call to merge on one class. Do the $element['#attributes']['class'] assignment and add form-radios.

  4. +++ b/core/modules/system/templates/radios.html.twig
    @@ -0,0 +1,17 @@
    + */
    + @todo: remove this file once http://drupal.org/node/1819284 is resolved.
    + This is identical to core/modules/system/templates/container.html.twig
    

    Remove the @todo, we'll take care of that when we do consolidation.

joelpittet’s picture

Issue tags: -Novice
FileSize
2.64 KB
PASSED: [[SimpleTest]]: [PHP 5.4 MySQL] 66,721 pass(es). View
1.63 KB

Took care of items in #18 and re-thought them a bit. I left the clobbering $attributes = array() and remove the unset, that's not something we need to deal with in this issue.

Status: Needs review » Needs work

The last submitted patch, 19: 2152221-twig-theme_radios-19.patch, failed testing.

joelpittet’s picture

joelpittet’s picture

joelpittet’s picture

Status: Needs work » Needs review
jjcarrion’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
29.67 KB

It works fine for me.

I've uploaded a screenshot.

LewisNyman’s picture

This looks identical to before, so success! RTBC++

Before:

After:

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed to 8.x. Thanks!

  • Commit 3b8d35a on 8.x by webchick:
    Issue #2152221 by IshaDakota, joelpittet, InternetDevels, rteijeiro |...

  • Commit ce9dc74 on 8.x by webchick:
    Revert "Issue #2152221 by IshaDakota, joelpittet, InternetDevels,...
  • Commit eed630f on 8.x by webchick:
    Issue #2152221 by IshaDakota, steveoliver, joelpittet, InternetDevels,...
webchick’s picture

Sorry, I messed up the commit credit on this one the first time. Good to know that the "commit-back" comments handle reverts, too. :)

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.