First of all, forgive me, this is my first attempt at twig. This patch: #1806426: Incorrect syntax in poll-results.twig causing it to fail needs to be committed before the following can be tested... create a poll and view the results to see the output.
I'm just wondering what needs to be done here to get the attributes ( e.g. data-max="1" data-value="1"
) to actually print in the template. Currently, everything works except for the HTML5 data attributes aren't printed, and the following error displays:
User error: "class" is an invalid render array key in element_children() (line 6251 of core/includes/common.inc).
User error: "class" is an invalid render array key in element_children() (line 6251 of core/includes/common.inc).
User error: "class" is an invalid render array key in element_children() (line 6251 of core/includes/common.inc).
Should a preprocess function be created for theme_meter to handle this portion of theme_meter?
$attributes = $variables['attributes'];
foreach (array('form', 'high', 'low', 'max', 'min', 'optimum', 'value') as $attribute) {
if (!empty($variables[$attribute])) {
// This function was initially designed for the <meter> tag, but due to
// the lack of browser and styling support for it, we're currently using
// it's attributes as HTML5 data attributes.
$attributes['data-' . $attribute] = $variables[$attribute];
}
}
I tried pulling it into the template itself, using something like the following, but I can't get anything but a list of the values to print out.. and it seems to me it shouldn't really be in the template anyway. Advice please?
{% for attribute in ['form', 'high', 'low', 'max', 'min', 'optimum', 'value'] %}
...
{% endfor %}
Comment | File | Size | Author |
---|---|---|---|
#16 | twig-theme-meter-orig.png | 14.35 KB | KrisBulman |
#16 | twig-theme-meter-mod.png | 13.86 KB | KrisBulman |
#9 | d8tts-theme-meter-twig-1806558-8.patch | 2.16 KB | KrisBulman |
#7 | d8tts-theme-meter-twig-1806558-5.patch | 732 bytes | KrisBulman |
d8tts-theme-meter-twig-1750250-1.patch | 1.43 KB | KrisBulman |
Comments
Comment #0.0
KrisBulman CreditAttribution: KrisBulman commentedadded link to patch
Comment #1
Fabianx CreditAttribution: Fabianx commentedKrisBulman: Thanks a lot for the work!
Please do:
preprocess
$variables['attributes'] = new Attribute($variables['attributes']);
theme:
or if the class is important:
Comment #2
anthonyR CreditAttribution: anthonyR commented@Fabianx:
I've seen this pattern before in the sandbox:
<tag class="{{ attributes.class }}" {{- attributes }}>
But this would give an empty class attribute if attributes.class is empty. Shouldn't we add checks for the property around the attribute everywhere this occurs?
Comment #3
Fabianx CreditAttribution: Fabianx commentedanthoyR: I know.
I think about using {{ attributes }}|merge({ class: ["my-class"] })
instead but I think its too complicated.
Maybe we can keep the "class" and use some twig cleanup magic.
Comment #4
anthonyR CreditAttribution: anthonyR commentedSorry for hijacking this issue, but it's something that occurs in almost every template.
This is one of the things we should decide a pattern for so that everyone uses it.
Otherwise we need to patch all the templates again when we decide what to do with it. Separate issue?
Comment #5
KrisBulman CreditAttribution: KrisBulman commentedRequested changes are now in and HTML5 attributes appear OK.
Note: there is a problem when adding new questions to a poll, this seems to be coming from theme_table, and should have nothing to do with this patch. Possibly related to #1778968: Convert theme_table to Twig
Comment #6
Fabianx CreditAttribution: Fabianx commentedCan you please add the patch?
Comment #7
KrisBulman CreditAttribution: KrisBulman commentedThat would help!
Comment #8
KrisBulman CreditAttribution: KrisBulman commentedsorry, let me reroll that. missing the twig template
Comment #9
KrisBulman CreditAttribution: KrisBulman commentedOK, here it is.
Comment #10
Fabianx CreditAttribution: Fabianx commentedHmm, this docs do not match that this is just in the attributes.
I have not seen original function, yet, but this unfortunately needs still some little work.
Good job so far!
Comment #11
KrisBulman CreditAttribution: KrisBulman commentedI don't follow, can you clarify please?
Here is what's in the original function:
API docs: http://api.drupal.org/api/drupal/core!includes!theme.inc/function/theme_meter/8
Comment #12
Fabianx CreditAttribution: Fabianx commentedWoops, my fault. Really sorry, looks seriously really good.
Could you attach some test code that calls this function for easy testing?
That would be totally great!
Just from looking at it, I'd say its RTBC, but I have not tested, yet.
Comment #13
KrisBulman CreditAttribution: KrisBulman commentedI'd love to, but not sure how to go about it, do we have any existing tests set up for converted functions to template_preprocess functions?
Here is the original documentation on how to override theme_meter, which dropped the data- from the html5 attribute and moved from a
<div>
to a<meter>
tag.Comment #14
Fabianx CreditAttribution: Fabianx commentedHere? Where is here?
Comment #15
KrisBulman CreditAttribution: KrisBulman commentedas usual, i forget the most important part
http://drupal.org/node/1432244
and this is the original ticket in which the function got created
http://drupal.org/node/1229442
Comment #16
KrisBulman CreditAttribution: KrisBulman commentedSteps to test this function:
output shows
modifying "data" to "foo" in the preprocess does change the attribute:
Whatever else you need I am willing to provide.
Comment #17
Fabianx CreditAttribution: Fabianx commentedThats very nice!
RTBC then!
Comment #18
psynaptic CreditAttribution: psynaptic commentedI'll test and commit this soon. Sorry about the delay.
Comment #19
podarokstatus
Comment #20
KrisBulman CreditAttribution: KrisBulman commentedOK, i see this needs work only based on your status change podarok, can you elaborate so it can be cleaned up?
Comment #21
podarokstatus change based on #18
Comment #22
KrisBulman CreditAttribution: KrisBulman commentedOK, if more testing is needed, it should be needs review
not sure what else I can do to move it forward without review
Comment #23
pixelwhip CreditAttribution: pixelwhip commentedThe patch in #9 looks good to me and works as expected. Marking back to RTBC.
Comment #24
podarok#9 commited / push to front-end
thanks!!!
Comment #25.0
(not verified) CreditAttribution: commentedupdated for clarification