super-table
super-table copied to clipboard
[4.x] $value can be instance of Collection
Describe the bug
The $value return value from $element->getFieldValue('superTableField') can be an instance of \craft\elements\Collection instead of craft\db\elements\ElementQuery
https://github.com/verbb/super-table/blob/craft-4/src/fields/SuperTableField.php#L868
/** @var SuperTableBlockQuery|Collection $value */
$value = $element->getFieldValue($this->handle);
// ... snip
$value->setCachedResult($blocks);
your IDE should complain about this line as setCachedResult does not exist in a Collection.
Could you please change this to
if (!$allBlocksValidate && $value instanceof ElementQuery) {
// Just in case the blocks weren't already cached
$value->setCachedResult($blocks);
}
Steps to reproduce
- Eager Load super table field value with invalid blocks due to changed validation rules
- see the error
Method craft\\elements\\ElementCollection::setCachedResult does not exist
Craft CMS version
4.X
Plugin version
3.0.12
Multi-site?
No
Additional context
No response
Fixed for the next release. To get this early, run composer require verbb/super-table:"dev-craft-4 as 3.0.12".
Thank you very much 🙇
Fixed in 3.0.13