[Image FT] Issue programmatically getting the cropped image
Created 7 years ago by damian_nz

I am using the Image FT and I need to programmatically get the cropped path. I know from the docs that I can do ->cropped()->path() on the presenter

I have the FT class (can dump it out) but if I run getPresenter() on that I get the standard FieldTypePresenter which doesn’t have the cropped method.

Do I need to instantiate the ImagePresenter and manually present? Or have I missed something that is causing the FT to have the wrong presenter?

ryanthompson  —  7 years ago

Try first decorating the entry with the decorator or the magic attribute:

$entry->decorated->image->cropped()->path();

Something like that should do it.

ryanthompson  —  7 years ago

That's weird you'd get the field type presenter though.. Ill have to check that out.

damian_nz  —  7 years ago

I think the issue is that my field is not known to the page entry (tsk tsk but maintaining old code).

I see in the FT class there is a couple times where it gets data using the entry.

For example this is in the decorate method

$value->setData(json_decode($this->entry->{$this->getField() . '_data'}));

What class should the entry be? and can I manually set the entry?

damian_nz  —  7 years ago

Oh also don't bother checking out the presenter issue. I tested the FT in normal use and it gets the correct presenter