Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 291113

Array tokens

$
0
0

Tokens are currently only available using 'named access', e.g. you have to specify a child token's name to access it. While modules can offer array access themselves—and Token.module does this already—it would be encouraging to developers to have support for this in core. A few requirements:

  1. Tokens should be able to access array items using named array keys and using indices. Note that numeric keys can be used for both indexed and associative arrays and without an explicit declaration there is no way of knowing whether numeric keys are indexes or named keys.
  2. Tokens should be able to access the nth array item from the start of the array, but also from the end of the array.

nth item access

The nth item from the start of the array can easily be accessed using a positive integer index. However, to select the nth item from the end of an array, negative indices may not be user friendly. If the original array is [array:items], can we offer an [array:items-reversed]?

indices versus named keys

Indices are always integers. Named keys can be integers (entity IDs, for instance) or strings. Should we require an explicit flag that specifies whether keys are named or just indices, so we can allow or disallow index access?


Viewing all articles
Browse latest Browse all 291113

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>