Jump to content

Single image is array in Pages::saveReady hook

Recommended Posts

I have an Images field that is set to required, maximum file = 1 and Single item (null if empty).

When I get the page in the front-end template the field if of ProcessWire\Pageimage (singular) type as I would expect but in a Pages::saveReady hook it is ProcessWire\Pageimages (plural).

Is this excepted behaviour — and if so, why? Is it to do with PW applying the “Single item (null if empty)” further down the chain?


EDIT: I think I have found the answer. It says this in the back-end:


Select the type of value you want this field to provide when accessed from the API on the front-end of your site.

I am assuming then that because the Pages::saveReady hook is called in the back-end this isn't applied. Instead, it is added some time before the template is loaded. So, fields Files and Images will always be arrays in the back-end/unless accessed via the templates. Is that right?

Link to post
Share on other sites

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...