From 67fdc9e9a7e2e1970006363f0ac73a6360ebe9d6 Mon Sep 17 00:00:00 2001 From: Bob den Otter Date: Tue, 23 Jun 2020 15:29:13 +0200 Subject: [PATCH 1/2] Ensure `$this->fields` is initialised (For Fields that haven't been accessed before) --- src/Entity/ListFieldTrait.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Entity/ListFieldTrait.php b/src/Entity/ListFieldTrait.php index 04d90fca5..48fbac12e 100644 --- a/src/Entity/ListFieldTrait.php +++ b/src/Entity/ListFieldTrait.php @@ -42,6 +42,9 @@ public function valid(): bool public function rewind(): void { + // Ensure $this->fields is initialised + $this->fields = $this->getValue(); + $this->iteratorCursor = 0; } } From 66fef6e365cff967439afa5391791aaf58bc07fc Mon Sep 17 00:00:00 2001 From: Bob den Otter Date: Tue, 23 Jun 2020 15:32:59 +0200 Subject: [PATCH 2/2] Update ListFieldTrait.php --- src/Entity/ListFieldTrait.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Entity/ListFieldTrait.php b/src/Entity/ListFieldTrait.php index 48fbac12e..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];