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

Fix src saving as an array and not as string #173

Merged
merged 1 commit into from
Oct 16, 2022
Merged

Conversation

ncla
Copy link
Collaborator

@ncla ncla commented Oct 14, 2022

Fixes #172.

As far as I understood, process method on fieldtypes is used for when field is being saved, and preProcess is for displaying the field. In ResponsiveFieldtype@process we are calling preProcess for all fields, when it should be just process. We are saving data there, not displaying.

Code from Assets fieldtype.

public function preProcess($values)
{
    if (is_null($values)) {
        return [];
    }

    return collect($values)->map(function ($value) {
        return $this->valueToId($value);
    })->filter()->values()->all();
}
public function process($data)
{
    $max_files = (int) $this->config('max_files');

    $values = collect($data)->map(function ($id) {
        return Asset::find($id)->path();
    });

    return $this->config('max_files') === 1 ? $values->first() : $values->all();
}

As you can see, core Assets fieldtype handles max_files being 1 only when saving. When preProcessing or displaying the data, it uses collection/array.

I am guessing you are not suppose to mix and match process and preProcess together in either one.

@ncla ncla merged commit 03aaddf into spatie:main Oct 16, 2022
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

Successfully merging this pull request may close these issues.

src values should be saved as string instead of an array in content files
1 participant