TopShelfCraft / Wordsmith

A plugin for Craft CMS to help you manage and manipulate text.
Other
30 stars 20 forks source link

Craft 4 getting Argument error on null variables #54

Closed aaronrobb closed 1 year ago

aaronrobb commented 2 years ago

I'm getting this error after a Craft 4 upgrade:

TopShelfCraft\Wordsmith\services\TypographyService::typogrify(): Argument #1 ($text) must be of type string, null given, called in /vendor/topshelfcraft/wordsmith/src/services/WordsmithService.php on line 1117

This is on a line of code like:

{{ item.title|typogrify }}

which worked on Craft 3.

Now the obvious issue is that on this specific page the tag is coming back null, but in Craft 3 that wasn't an issue.

When I add something like:

{{ item.title ?? "" |typogrify }}

it allows the page to load, but then for some reason if the text field had code in it, like a <br> tag, it shows the code.

I can wrap the whole tag in an 'IF' statement, but there has to be a shorter way, like above, but without the code showing.

Is this a known issue, or am I missing something?

michaelrog commented 2 years ago

Hmmmm, sounds like a PHP8/types gotcha. I'll check it out.

mmoss128 commented 1 year ago

Ran into the same issue. Modifying TypographyService.php and changing the function declaration for typogrify from public function typogrify(string $text, array $adhocSettings = []): string to public function typogrify(string|null $text, array $adhocSettings = []): string looks to resolve the issue.

michaelrog commented 1 year ago

Fixed in 4.1.0. Thanks!