thuijzer Posted June 22, 2018 Posted June 22, 2018 First I like to say that the new(ish) focus function for images is really great! But I can't seem to save focus via the API. Does anyone know how to do this? I tried all methods described in Pageimage.php: $member->avatar->focus($top, $left); $member->save(); $member->avatar->focus($top . ' ' . $left); $member->save(); $member->avatar->focus([$top, $left]); $member->save(); But whatever I try, the focus is never updated/saved. Extra note: in de database the field "filedata" becomes empty when I use the methods described above.
Soma Posted June 22, 2018 Posted June 22, 2018 Just doing this in my basic-page template works fine: $page->of(false); foreach($page->images as $img) { $img->focus("10%", "10%"); } $page->save(); $page->of(true);
thuijzer Posted June 22, 2018 Author Posted June 22, 2018 30 minutes ago, Soma said: Just doing this in my basic-page template works fine: $page->of(false); foreach($page->images as $img) { $img->focus("10%", "10%"); } $page->save(); $page->of(true); Yes. This is indeed how I thought it should work. I just discovered that it only works when I create a new image. For example: // this works: $member->of(false); $member->avatar = $filename; // avatar becomes a \ProcessWire\PageImages $member->avatar->first->focus(10, 10); $member->save(); $member->of(true); // this does not work: $member->of(false); $member->avatar->first->focus(50, 50); // avatar already is a \ProcessWire\PageImages $member->save(); $member->of(true); By the way: $member is a \ProcessWire\User but I don't think this should be the problem. So I guess I'm doing something else wrong. Thank you for your reply!
Soma Posted June 22, 2018 Posted June 22, 2018 Make sure you work with a Pageimage and not Pageimages or something else. It works perfectly. You do $member->avatar->first->focus(10, 10); but before you did $member->avatar->focus(10, 10);
thuijzer Posted June 25, 2018 Author Posted June 25, 2018 Yes I made sure I'm working with a Pageimage, but I still don't get it. What I see: The focus of an existing image is updated in the model (avatar field). The "changes" property is updated to notify that "filedata" is changed. When I save the model it returns 'true'. When I debug all database queries I see the model's modified date is updated, but the new focus is never stored. When I change the function PageFiles::resetTrackChanges so that nothing gets reset, the new focus is stored in the database. So somewhere along the way the "changes" property is reset for the avatar field, but I can't figure out when and why. Going to dive deeper into this ?
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now