Jump to content
Gideon So

Set image focus through API

Recommended Posts

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

 

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...