Jump to content

Recommended Posts

Posted

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

 

Posted

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);

 

  • Like 3
Posted

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

  • 3 years later...
Posted

…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
Posted

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.

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...