jacksleight / statamic-distill

This Statamic addon allows you to filter, fetch or index the individual values, sets and relations within your entries, from both root and deeply nested fields.
https://statamic.com/addons/jacksleight/distill
MIT License
9 stars 1 forks source link

Fieldtype data lost in extractText in 4.x site #8

Closed simonerd closed 2 months ago

simonerd commented 3 months ago

Bug Description

I'm using Distill in a search transformer for a bard field within a Statamic 4 site. The field has several sets (e. g. accordions, images with description etc.) and is plugged into Distill as described in the readme:

public function handle($value, $field, $searchable)
{
      return Distill::text($searchable->augmentedValue($field));
}

Unfortunately, this always results in an error "Call to a member function handle() on null", pointing to the extractText method (link to code). In L103 all items are mapped into the augmentedValue function which leads to loosing the fieldtype data that is required in L104 ($value->fieldtype()->handle()), leading to the error.

It looks like the changes introduced in 0.6.4 cause the error. When changing the first map (L103) back to ->map->value (as it was before), the error disappears and the search transformer gets the correct data. Haven't looked into this more throughly, maybe the 0.6.4 changes are simply incompatible with v4.

I'd probably be fine with simply fixing 0.6.3 for now until the site is updated to v5. However, if it really would be an incompatibility issue, the composer.json should be adjusted, I suppose.

How to Reproduce

v4 site, bard field with sets (haven't tested if sets are relevant), search transformer as described above.

Extra Detail

n/a

Environment

Environment
Application Name: myapp
Laravel Version: 10.48.10
PHP Version: 8.2.13
Composer Version: 2.7.6
Environment: local
Debug Mode: ENABLED
URL: myapp.localhost
Maintenance Mode: OFF

Cache
Config: NOT CACHED
Events: CACHED
Routes: CACHED
Views: CACHED

Drivers
Broadcasting: null
Cache: redis
Database: mysql
Logs: daily
Mail: smtp
Queue: redis
Session: file

Statamic
Addons: 9
Antlers: runtime
Sites: 2 (Deutsch, English)
Stache Watcher: Enabled
Static Caching: Disabled
Version: 4.57.3 PRO

Statamic Addons
jacksleight/statamic-distill: 0.7.0
statamic-rad-pack/meilisearch: 3.2.1
visuellverstehen/statamic-anchor-navigation: 0.3.6-beta
visuellverstehen/statamic-classify: 2.6.2
visuellverstehen/statamic-content-renderer: 1.0.1
visuellverstehen/statamic-glossary-tooltips: dev-main
visuellverstehen/statamic-picturesque: 1.4.5
visuellverstehen/statamic-pixxio-flysystem: dev-main
visuellverstehen/statamic-sourcestack: 1.0.1
jacksleight commented 3 months ago

Ah that's no good, v4 should still be supported. I'll see if there's a fix that works in both.

Thanks for the detailed report!

simonerd commented 3 months ago

Thanks for the detailed report!

Sure, happy to help. Thanks for the helpful chat at FlatCamp! 😉

jacksleight commented 2 months ago

Fixed in v0.7.1.