Skip to content
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

Linked replicator in fieldset causes `Illegal string offset 'type' #2677

Closed
jawngee opened this issue Oct 18, 2020 · 3 comments
Closed

Linked replicator in fieldset causes `Illegal string offset 'type' #2677

jawngee opened this issue Oct 18, 2020 · 3 comments

Comments

@jawngee
Copy link

jawngee commented Oct 18, 2020

Bug Description

I have a collection that links to a fieldset that a few other collections use. The fieldset is a replicator with a variable number of sets.

Creating a new entry in that collection without adding anything to the linked replicator causes the Illegal string offset 'type' exception after saving it and navigating back to it.

Interestingly, this doesn't happen if the collection's blueprint only contains the linked replicator, but if you add other fields to the collection's blueprint the error occurs.

How to Reproduce

  1. Create a field set that contains a replicator.
  2. Create a new collection
  3. In the new collection's blueprint add any field and add a field linked to the field set.
  4. Create a new entry and save it without adding content to linked replicator field.
  5. Navigate away and then back to the entry.

I've attached yaml configs: statamic-fieldset-bug.zip

Extra Detail

The error happend in line 47 of vendor/statamic/cms/src/FieldStypes/Replicator.php

I think the actual issue is further up the stack in:

$value = $this->value ?? $this->defaultValue();

The issue is that an empty string makes it's way to line 47 of the Replicator, but because you are using a null coalescing operator (which doesn't work on empty strings) - the default value isn't being assigned.

So line 209 in Field.php should be rewritten with the elvis operator:

$value = $this->value ?: $this->defaultValue();

Environment

Statamic version: 3.0.19
Laravel: 8.10.0
PHP version: 7.4

Install method (choose one):

  • Fresh install from statamic/statamic
@jawngee
Copy link
Author

jawngee commented Oct 20, 2020

This is happening in Replicator.php too on line 102:

if (! $this->config("sets.{$set['type']}.fields")) {

It's the same deal. The value that makes it way to that method is an empty string where it's expecting an array. I had to add the following:

        if (empty($this->raw)) {
            return $this->raw;
        }

To Value.php at line 45:

public function value()

Obviously this is a deeper issue and I'm just whackamoling so I can get it to work. I read in other issues that having the linked replicator field named 'content' was causing issues before, but that issue was resolved in 3.x?

@jasonvarga
Copy link
Member

This is indeed because you've named it content. Thanks!

@alexolder
Copy link

This is still an issue in 3.1.18 when trying to reference a replicator in a fieldset.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants