Problem/Motivation
Regular elements constructed in buildForm() render with an ID. Also, the container gets the same ID. So, the page has two elements with the same ID.
Example:
<?php
$form['system_compact_link'] = array(
'#type' => 'system_compact_link',
}
?>
We were able to work around this in the linked issue by adding:
<?php
'#id' => FALSE,
?>
Proposed resolution
Do not add an ID attribute to an element that already has a container with the same ID.
Remaining tasks
First of all, should Form building allow non-form types? or, is this change actually needed?
Write a test.
Decide on how to fix it. If going with the current solution, fix remaining test fail.
Original report by @lokapujya
Follow-up to #1833932: Convert theme_system_compact_link() into a #type link
Comment | File | Size | Author |
---|---|---|---|
#26 | interdiff-2347209-24-26.txt | 1.69 KB | heykarthikwithu |
#26 | 2347209-26.patch | 2.18 KB | heykarthikwithu |
#24 | 2347209-24.patch | 3.29 KB | lokapujya |
#22 | 2347209-22-test-only.patch | 3.29 KB | lokapujya |
#20 | 2347209-18b-test-only.patch | 2.17 KB | lokapujya |
Comments
Comment #1
lokapujyaThis code demos where the IDs get added. The patch gets rid of both IDs. Not sure if we should change the render code or use ['#markup'] = drupal_render().
Comment #2
lokapujyaComment #4
lokapujyaComment #6
lauriiiComment #8
lokapujyaattempt to fix 1st test fail, by not removing id for containers.
Comment #10
star-szrAdding a loosely related issue.
Comment #11
lokapujyaComment #12
star-szrSo I guess this is a bug/task? Please update the issue summary/category as appropriate. This line of code is a bit complex so should probably have a code comment to explain the logic and we'd want to add tests as well.
Thanks @lokapujya!
Comment #14
lokapujyaComment #15
lokapujyaComment #16
lauriiiRe uploading the previous patch to see results on new test bot
Comment #18
lokapujyaComment #20
lokapujyaComment #22
lokapujyaFile missing from patch, Don't know why that happened.
Comment #24
lokapujyaStill needs a comment for line mentioned in #12:
Something like this, but it doesn't sound right to me:
// If the element is a container or if the wrapper is the not the same type as the element then add an ID.
Comment #26
heykarthikwithuComment #28
lokapujyaWhy was this deleted?
Also, any clue to why the test is still failing?
Comment #43
luke.stewart CreditAttribution: luke.stewart commentedI've just attempted to replicate this on 10.2.4
I created a custom module using drush generate simple:form and installed
In the form I created the following insight the generated buildForm method
When I inspect the elements on the page rendered I see a control with an id 'edit-atextfield' which has a wrapper div with id 'edit-acontainer'
If this doesn't demonstrate the problem please include some clear steps to reproduce.