1

I have a task that is used to collate relationship data for a specific entry and save it as JSON to a text field in that entry. Everything is working fine, except for the saving of the entry which fails because the required Matrix / Assets fields in the entry are being read as blank. I've checked to make sure that the entries have all required fields completed, but the errors still persist.

The entry saving code in the task:

$entry->getContent()->setAttribute('latLngs', json_encode($latLngs));

craft()->entries->saveEntry($entry);

The errors being returned:

[_errors:CModel:private] => Array
(
    [gallery] => Array
    (
        [0] => Gallery cannot be blank.
    )
    [standardContent] => Array
    (
        [0] => Standard Content cannot be blank.
    )
)

Where gallery is an Assets field, and standardContent is a Matrix field. All other required fields seem to be working fine with no errors.

Is this to do with the way I'm saving the entries, or something else?

Thanks!

1

This is due to the way Craft manages custom fields at the moment (but has been “fixed” for Craft 3). Whenever you save an element, you need to make sure all of the field values are in the same format they would be if they had come from an Edit Entry form submission. Here’s another post that describes what that looks like: How to save a matrix content of a new entry in my plugin?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.