super-table icon indicating copy to clipboard operation
super-table copied to clipboard

[4.x] $value can be instance of Collection

Open Anubarak opened this issue 1 year ago • 2 comments

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

  1. Eager Load super table field value with invalid blocks due to changed validation rules
  2. 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

Anubarak avatar Apr 15 '24 14:04 Anubarak

Fixed for the next release. To get this early, run composer require verbb/super-table:"dev-craft-4 as 3.0.12".

engram-design avatar Apr 17 '24 03:04 engram-design

Thank you very much 🙇

Anubarak avatar Apr 17 '24 07:04 Anubarak

Fixed in 3.0.13

engram-design avatar May 20 '24 09:05 engram-design