Needs work
Project:
Drupal core
Version:
main
Component:
base system
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
27 Sep 2015 at 17:41 UTC
Updated:
21 Feb 2025 at 02:05 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
alexpottComment #5
alexpottAh Attribute was why I didn't do this originally but this was a mistake.
Comment #6
dawehnerDoes that mean we need a test for that behaviour?
Comment #10
dawehnerComment #19
smustgrave commentedComment #20
longwaveCountable::count()must be declared asintreturn type in PHP 8.Comment #21
smustgrave commented@longwave not sure I know what you mean? Like you want it as
public function count(): int;Comment #22
longwaveThe error that DrupalCI is reporting is
Comment #23
ravi.shankar commentedTrying to fix comment #22.
Comment #24
bruno.bicudoTrying to fix #23. Kindly review it.
Comment #25
alexpottThere's no need for MarkupInterface to define count - that's coming from \Countable.
Comment #26
alexpottThis one is interesting. I think we should implement this has
return count($this->storage);because this is an array of strings and implements ArrayAccess so it's not really the same as other things here.Comment #27
pooja saraah commentedAddressed comment #26
Attached interdiff patch
Comment #28
alexpottLooking at twig_length_filter(), twig_test_empty() yeah I think we should do ##2 it means we won't render attributes twice.
Here's what twig_test_empty() is doing:
Hmmm... on the other hand this new implementation is more consistent with expectations! Because we're only providing a positive count when something is rendered... i.e we are accounting now for the logic in
So actually the current implementation of \Drupal\Core\Template\Attribute::count() is not right - you can't call count() on a string in PHP 8.1 without generating a deprecation. The patch attached fixes this. Hmmm... this is all very tricky. At the moment Twig is using the
For attributes however this is giving the wrong answer for an attribute like this:
Because it will give the answer of 1 rather than 0 but such an attribute will render to an empty string.
What do we want an attribute object such as the one above to count to? Looking at twig_test_empty() I think we want it to count to 0 as nothing will be rendered.
Comment #29
alexpottMaking the test more explicit about how ArrayAttributes are counted... maybe we should change that. Not sure.
Comment #30
alexpottRe #29 - yeah I think we should be more elegant here. And count the number of class in the count. So something like this:
Comment #31
longwave#30 is the same as #29?
Comment #32
smustgrave commentedCompared #29 and #30 and it does appear to be the same patch.
Comment #33
alexpottHere's the patch I meant to upload.
Comment #34
alexpottNow looking at #33 I'm not so sure that it is better than #30 ... like count on the attributes object should return the number of attributes that would be printed... so additional classes should not affect the count...
Comment #35
smustgrave commentedSo should this move back to NW ?
Comment #37
smustgrave commentedSeems there is still discussion.
Think whatever solution there is should be added to the issue summary.
Comment #39
acbramley commentedCame up in BSI. Is this still relevant? Looks like we still need an IS update and now need a reroll on to an MR if so.