Merge branch '1.x' into 2.x

* 1.x:
  Throw exception in case non-Traversable data is passed to "filter" filter
  Improve batch code example
This commit is contained in:
Fabien Potencier
2020-06-08 12:41:25 +02:00
2 changed files with 5 additions and 6 deletions
+1 -6
View File
@@ -7,7 +7,7 @@ missing items:
.. code-block:: twig
{% set items = ['a', 'b', 'c', 'd', 'e', 'f', 'g'] %}
{% set items = ['a', 'b', 'c', 'd'] %}
<table>
{% for row in items|batch(3, 'No item') %}
@@ -31,11 +31,6 @@ The above example will be rendered as:
</tr>
<tr>
<td>d</td>
<td>e</td>
<td>f</td>
</tr>
<tr>
<td>g</td>
<td>No item</td>
<td>No item</td>
</tr>
+4
View File
@@ -1537,6 +1537,10 @@ function twig_array_column($array, $name, $index = null): array
function twig_array_filter($array, $arrow)
{
if (!twig_test_iterable($array)) {
throw new RuntimeError(sprintf('The "filter" filter expects an array or "Traversable", got "%s".', \is_object($array) ? \get_class($array) : \gettype($array)));
}
if (\is_array($array)) {
return array_filter($array, $arrow, \ARRAY_FILTER_USE_BOTH);
}