0

I've created a custom fieldtype for "links" which have three input fields (URL, label and target). It works very well and I've now added the only required method to the class in Matrix which is display_cell() (according to the documentation).

My field displays fine, but when I save the entry and edit it again, no data is present in my field.

If I add save_cell() to my class and return some debug data, it is saved to the entry and displayed, but if I just return the data that it is supposed to receive in the method params, I get nothing.

I can, however, force the data to save by fetching it from the post array, as shown here:

function save_cell($data)
{
    return json_encode(ee()->input->post($this->settings['field_name']));
}

Obviously, I don't want to do this but $data is always empty! Any ideas why?

Thanks, Mat

UPDATE: I've answered this below

1 Answer 1

1

Resolved! I wasn't using $this->cell_name when displaying my field in display_cell() so EE wasn't able to get the data from the form because it had the wrong name. The method shown in my question will try to get the data from the matrix field, not the row within the matrix field. The actual name of a cell within a matrix ROW looks something like this:

field_id_35[row_id_85][col_id_14][url]

[url] is an array element I added to split the field into three parts (url,label,target).

Now my save function just returns $this->save($data) because I don't need to do anything different to the save() method (which simply json_encodes the three parts).

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.