-
-
Notifications
You must be signed in to change notification settings - Fork 530
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[5.x] Fix error when augmenting Bard fields #10104
Conversation
Good catch! Just two points:
|
Yeah, that makes sense.
Oh interesting... do you have a set called |
No, but the error occurred on a Bard field that I had content both directly in the editor and in sets. I mix and match them sometimes, probably shouldn't, but it's easier if I have a lot of text with only a couple of sets here and there for rich content. This check |
Mixing & matching them is fine. I'm just trying to figure out what might be causing the error in the first place if you don't have a |
Maybe the fact that the default set is |
If just having text in a bard field is enough to trigger it then we should be hearing many more reports about this issue. 🤔 |
I am only getting it when using json_encode, not normal Antlers. Whatever the reason it is fixed with this PR through. |
text
set
Can you show how you are using it? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue stated that the error only started happening since 4.42.1, which points to #9198. So, I think the fix should be something to do with that. The is_string()
fails because its a Value
instance, even though it would evaluate to a string.
Maybe something like:
protected function performAugmentation($value, $shallow)
{
- if ($this->shouldSaveHtml() && $isString) {
+ $isString = is_string($value)
+ || ($value instanceof Value && is_string($value->value()));
+
+ if ($this->shouldSaveHtml() && is_string($value)) {
The test you've written does sorta test this, but it's confusing. I can't make sense of this nested mapping and toArray.
$this->assertEquals($expected, collect($augmented)->map->all()->map(fn ($items) => collect($items)->map(fn ($value) => (string) $value))->toArray());
I'd prefer to figure out a way to write a test that better represents what is happening in reality.
I'm using it in the nav tag to send the navigation to a Vue component.
I've narrowed it down to the main Bard content field throwing that error. Note that using the
I get the exact same error. It is caused by empty lines in the Bard field like The Bard field in question is in a fieldset that I then link around in different collections:
It's doesn't have |
I returned to this site and unfortunately the fix by @jasonvarga doesn't seem to work. The original fix by Duncan does. Can I somehow help debug this? |
This pull request fixes an issue when augmenting Bard fields with a
text
set configured.The issue
After some digging, it seems like the error is being caused by writing text directly in a Bard field, while also having a Bard set called
text
, with a subfield also calledtext
that isn't a Text field.For example:
modules
.text
.text
When augmenting the Bard text, because both the set & the field are called
text
, it used the Bard fieldtype to try and augment the text:The "inline" Bard text was being augmented to a Text field (which is correct).
However, in here, another
Value
object was being created using the Bard fieldtype and theValue
object just created for augmenting the Text field was passed in as the "raw" value.The issue then happened when you tried to use that text field in Antlers, since that's when it'll call the
Bard::performAugmentation
method, with theValue
object passed as the$value
.Previously, before #9198 was merged, it worked by fluke since it'd get caught by the
$this->shouldSaveHtml()
conditional and just return back theValue
object but since we added theis_string
conditional, thatValue
object then made its way down all the Bard augmentation stuff which isn't expecting aValue
object.The fix
This PR fixes the issue by adding a check to
Augmentor::augmentSets
to catch any text values that have already been wrapped in aValue
object.I've added a test to ensure this edge case gets handled properly and another one to ensure I didn't cause a regression of #9198.
_^ Hopefully this brain dump makes sense. If it doesn't let me know. 😆 _
Closes #9352.