jacksleight / statamic-bard-mutator

This Statamic addon allows you to modify the data and tags rendered by the Bard fieldtype, giving you full control over the final HTML.
https://statamic.com/addons/jacksleight/bard-mutator
MIT License
19 stars 3 forks source link

Missing `info` object causing fatal error when mutating links #34

Closed daun closed 1 week ago

daun commented 1 week ago

Bug Description

After upgrading to 3.0, I'm getting the following error when mutating links.

JackSleight\StatamicBardMutator\Plugins\ClosurePlugin::render()
Argument #2 ($info) must be of type object, null given, called in
vendor/jacksleight/statamic-bard-mutator/src/Mutator.php
on line 168

How to Reproduce

I'm using the example from the docs for marking external links.

Mutator::html('link', function ($value) {
  if (URL::isExternal($value[1]['href'])) {
    $value[1]['class'] = 'external';
  }
  return $value;
});

This is the Bard field data in question that throws. Removing it also gets rid of the exception.

  -
    type: paragraph
    attrs:
      textAlign: left
      bts_key: null
    content:
      -
        type: text
        marks:
          -
            type: link
            attrs:
              href: 'statamic://entry::2c469569-6697-460a-ba15-b4e1d3842c3f'
              rel: null
              target: null
              title: null
        text: 'Read more'

That's the url that throws:

/manage/collections/pages/entries?sort=updated_at&order=desc&page=1&perPage=10

Extra Detail

It looks like for some reason the $info var fetched from Mutator::fetchInfo() is empty for that particular node. That's where I'm getting lost on the inner workings of the addon, though :)

Environment

Environment
Application Name: *****
Laravel Version: 11.26.0
PHP Version: 8.3.4
Composer Version: 2.5.5
Environment: local
Debug Mode: ENABLED
URL: *****.test
Maintenance Mode: OFF
Timezone: Europe/Vienna
Locale: en

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

Drivers
Broadcasting: log
Cache: file
Database: sqlite
Logs: stack / single
Mail: log
Queue: database
Session: file

Statamic
Addons: 5
Sites: 1
Stache Watcher: Enabled
Static Caching: Disabled
Version: 5.30.0 PRO

Statamic Addons
daun/statamic-widget-collection-count: 1.2.1
doefom/currency-fieldtype: 1.4.1
jacksleight/statamic-bard-mutator: 3.0.0
jacksleight/statamic-bard-texstyle: 3.3.0
stillat/relationships: 2.2.1
daun commented 1 week ago

Update: this only happens when fetching entries from the control panel json endpoint, not when mutating in the frontend view itself. So it reliably happens when displaying entries from a collection dashboard panel, or when rendering a Bard field in the entries listing. Might have to do with the augmentation state of the bard content field?

jacksleight commented 1 week ago

Thanks for the report and details! Fixed in v3.0.1.

daun commented 1 week ago

Amazing — thanks for the quick fix!

lvmbard commented 4 days ago

Unfortunately, this still isn't fixed for me - it seems like the change in 3.0.1 is just a change to the log file?

https://github.com/jacksleight/statamic-bard-mutator/commit/75e64b3579e933738a3a6fe621306d6d3676a037

daun commented 4 days ago

@lvmbard Installing 3.0.1 definitely fixed the issue here. If you look at the comparison between 3.0.0 and 3.0.1, you'll see it contains more than the commit you've linked.

lvmbard commented 4 days ago

@daun Thanks for the quick reply - we've freshly installed 3.0.1 and still experience this same error when using the below example from the docs:

Mutator::html('table', function ($value) {
    $inner = array_splice($value, 2, count($value), [0]);
    $value = ['div', ['class' => 'table-wrapper'], $value, ...$inner];
    return $value;
});
jacksleight commented 3 days ago

@lvmbard Could you share the output from php please support:details and let me know exactly where you're seeing the error, a full stack trace would also be really helpful if possible.

I'm away right now but I'll take a look when I'm back.

lvmbard commented 3 days ago

@jacksleight Thanks for getting back to me, here's the output of that command:

Environment
Application Name: *****
Laravel Version: 11.23.5
PHP Version: 8.3.10
Composer Version: 2.7.4
Environment: local
Debug Mode: ENABLED
URL: *****
Maintenance Mode: OFF
Timezone: UTC
Locale: en

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

Drivers
Broadcasting: log
Cache: file
Database: mysql
Logs: stack / single
Mail: smtp
Queue: sync
Session: cookie

Sentry
Enabled: MISSING DSN
Environment: local
Laravel SDK Version: 4.8.0
PHP SDK Version: 4.9.0
Release: NOT SET
Sample Rate Errors: 100%
Sample Rate Performance Monitoring: 20%
Sample Rate Profiling: 100%
Send Default PII: DISABLED

Statamic
Addons: 2
Sites: 3
Stache Watcher: Enabled
Static Caching: Disabled
Version: 5.24.0 PRO

Statamic Addons
jacksleight/statamic-bard-mutator: 3.0.1
statamic/eloquent-driver: 4.14.0

Statamic Eloquent Driver
Asset Containers: eloquent
Assets: eloquent
Blueprints: eloquent
Collection Trees: eloquent
Collections: eloquent
Entries: eloquent
Forms: eloquent
Global Sets: eloquent
Global Variables: eloquent
Navigation Trees: eloquent
Navigations: eloquent
Revisions: eloquent
Sites: file
Taxonomies: eloquent
Terms: eloquent
Tokens: file

The issue occurs when trying to edit a page within the admin panel (the same page will work fine on the frontend).