verbb / super-table

Super-charge your Craft workflow using Super Table.
MIT License
316 stars 47 forks source link

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

Closed Anubarak closed 6 months ago

Anubarak commented 7 months ago

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

engram-design commented 7 months ago

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

Anubarak commented 7 months ago

Thank you very much 🙇

engram-design commented 6 months ago

Fixed in 3.0.13