diff --git a/src/Entity/ListFieldTrait.php b/src/Entity/ListFieldTrait.php index 04d90fca5..9c85c989c 100644 --- a/src/Entity/ListFieldTrait.php +++ b/src/Entity/ListFieldTrait.php @@ -20,6 +20,15 @@ public function count(): int return count($this->getValue()); } + /** + * Makes ListFieldInterface fields .length attribute + * return the number of elements in the field + */ + public function length(): int + { + return $this->count(); + } + public function current(): Field { return $this->fields[$this->iteratorCursor]; @@ -42,6 +51,9 @@ public function valid(): bool public function rewind(): void { + // Ensure $this->fields is initialised + $this->fields = $this->getValue(); + $this->iteratorCursor = 0; } }