TokenFieldRender.php in Token 8
File
src/TokenFieldRender.php
View source
<?php
namespace Drupal\token;
use Drupal\Core\Security\TrustedCallbackInterface;
use Drupal\Core\Render\Element;
class TokenFieldRender implements TrustedCallbackInterface {
public static function trustedCallbacks() {
return [
'preRender',
];
}
public static function preRender($elements) {
unset($elements['#theme']);
unset($elements['#states']);
unset($elements['#attached']);
$deltas = Element::getVisibleChildren($elements);
$count = count($deltas);
if ($count > 1) {
$join = isset($elements['#token_options']['join']) ? $elements['#token_options']['join'] : ", ";
foreach ($deltas as $index => $delta) {
if ($index < $count - 1) {
$elements[$delta] += [
'#suffix' => $join,
];
}
}
}
return $elements;
}
}