Gideon So Posted May 15, 2019 Share Posted May 15, 2019 Is it possible to set page image focus through a hook?? I tried this piece of code but it seems doesn't work. wire()->addHookAfter('Pages::saveReady', function ($event) { $page = $event->arguments(0); if(count($page->pageBanner)){ $page->of(false); $page->pageBanner->focus(10,10); $page->save(); $page->of(true); } }); Processwire throw this error: Quote Method Pageimages::focus does not exist or is not callable in this context Any ideas is much welcome. Gideon Link to comment Share on other sites More sharing options...
Robin S Posted May 15, 2019 Share Posted May 15, 2019 When output formatting is off the value of a Images field is a Pageimages object (WireArray). So you have to do: $page->pageBanner->first()->focus(10,10); 3 Link to comment Share on other sites More sharing options...
Gideon So Posted May 16, 2019 Author Share Posted May 16, 2019 I see. Learn a lesson. Thanks @Robin S Gideon 1 Link to comment Share on other sites More sharing options...
Gideon So Posted May 16, 2019 Author Share Posted May 16, 2019 In case someone need the solution: wire()->addHookBefore('Pages::saveReady', function ($event) { $page = $event->arguments(0); if(count($page->pageBanner)){ $page->of(false); $page->pageBanner->first()->focus([top],[left]); $page->of(true); } }); Gideon Link to comment Share on other sites More sharing options...
froot Posted December 15, 2022 Share Posted December 15, 2022 …doesn't work if you also set a size? like: $thumb = $foo->images->first->focus(0,0); // works $thumb = $foo->images->first->size(400, 400)->focus(0,0); // doesn't work Link to comment Share on other sites More sharing options...
Jan Romero Posted December 15, 2022 Share Posted December 15, 2022 I feel like it would make more sense to call focus() first and size() afterwards, but I haven’t tested or read up on anything. 2 Link to comment Share on other sites More sharing options...
froot Posted December 16, 2022 Share Posted December 16, 2022 I don't know and it's very hard to find out because everything image related in the CMS is very unreliable for lack of a better word. I don't know if the images are cached somewhere, on the server, in the browser? Any changes I take don't have any effect, setting the image focus manually in the input dialogue, not even rotating or flipping changes anything. I delete all image variations, rename the images, nothing helps. All stays the same so it's hard to say if the API is correct or not. Link to comment Share on other sites More sharing options...
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