Skip to content

Commit

Permalink
Merge pull request #1544 from bolt/bobdenotter-patch-1
Browse files Browse the repository at this point in the history
Ensure `$this->fields` is initialised (For Fields that haven't been accessed before)
  • Loading branch information
bobdenotter committed Jun 24, 2020
2 parents 58e4e57 + 66fef6e commit 7c2a13e
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/Entity/ListFieldTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -42,6 +51,9 @@ public function valid(): bool

public function rewind(): void
{
// Ensure $this->fields is initialised
$this->fields = $this->getValue();

$this->iteratorCursor = 0;
}
}

0 comments on commit 7c2a13e

Please sign in to comment.