The issue for the 2.0.x branch of #3342390: Make the Twig loops safer

Let's not forget the prerender.

Comments

pdureau created an issue. See original summary.

pdureau’s picture

Title: [2.0.0-alpha2] Add sequance and mapping tests » [2.0.0-alpha2] Add sequence and mapping tests
Issue summary: View changes
pdureau’s picture

Title: [2.0.0-alpha2] Add sequence and mapping tests » [2.0.0-alpha3] Add sequence and mapping tests

https://github.com/twigphp/Twig/issues/3828 has resumed!

So, if you want to wait the upstream, this issue will only be for the prerender.

Moved to alpha3

pdureau’s picture

Status: Active » Needs work
pdureau’s picture

Upstream PR ready for review: https://github.com/twigphp/Twig/pull/3859

pdureau’s picture

Title: [2.0.0-alpha3] Add sequence and mapping tests » [2.0.0-beta1] Add sequence and mapping tests
Status: Needs work » Postponed

Waiting upstream news

pdureau’s picture

Merged: https://github.com/twigphp/Twig/commit/045f5adec773f6430676fdda078b2fa39...

So, we keep this issue for this remaining task.

However, is sequence test is not enough when a list of renderables has mapping keys (non consecutive, strings) instead of sequence (integer, consecutive) keys.

For example a list of blocks from page layout or layout builder: each block is keyed by its UUID.

In other words:

  • in Drupal, a unique renderable is always an associative array ("mapping"). In Twig, it is always a mapping. So it is OK.
  • in Drupal, a list of renderables can be a list array ("sequence") or sometimes an associative array ("mapping"). In Twig, it must always be a sequence.
  • When a list of renderables is an associative array in Drupal, the keys are meaningless, just traversable, and can be removed. So let's remove them before sending them to Twig in a prerender method.
  • UI Patterns is a perfect place to do that because we know which variables expects renderables (slots/fields) and which are not (props/settings). It would not be easy at a Drupal core level. Same with #3383544: [2.0.0-beta5] Empty field values when not renderable

So, add a rule to SlotPropType::normalize() to transform this list of renderable to a proper Twig sequence, on the first level of each slot, no recursivity.

Be careful to not break layout builder :)

1.x implementation has its own specific issue : #3342390: Make the Twig loops safer

pdureau’s picture

Title: [2.0.0-beta1] Add sequence and mapping tests » [2.0.0-beta1] Normalize list of renderables in slots

  • pdureau committed c66fc5d0 on 2.0.x
    Issue #3422265 by pdureau: Normalize list of renderables in slots
    
pdureau’s picture

Assigned: pdureau » Unassigned
Status: Postponed » Fixed

Status: Fixed » Closed (fixed)

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