How do I get a page's media onAdminSave if the page is a flex object?

The plugin Resize Images isn’t working anymore since Grav pages have become flex objects by default. (I have since discovered that you can turn this behaviour off in the flex objects settings, but sometimes pages as flex objects are very useful.) This is because it checks onAdminSave whether the saved object is a page like this:

public function onAdminSave($event)
{
    $page = $event['object'];
    dump($event);

    if (!$page instanceof Page) {
        return false;
    }
[…]
}

As you can see I put in a dump($event) to see what it looks like now, but that doesn’t actually do anything?! How do I get the attached media files from a flex object page?

Thank you for your time and thoughts!

@Netzhexe, Try the following in ‘/user/plugins/resize-images/resize-images.php’:

  • Import the new Flex page object
    use Grav\Common\Flex\Types\Pages\PageObject;
    
  • When a flex page is being saved, $event contains ‘page’ instead of ‘object’
    public function onAdminSave($event)
    {
        $page = $event['object'] ?? $event['page'];
    
        if (!$page instanceof Page && !$page instanceof PageObject) {
            return false;
        }
    

Resized images are now being generated for regular and flex pages.

Note: Not sure if the change of $event is by design or a bug. It is a breaking change for sure. I’ve added an issue on the Admin repo.

Depending on whether it is by design or a bug, you might consider creating a PR In response to issue Plugin does not resize images when used in Grav v1.7.0-rc.7 - Admin v1.10.0-rc.7 #21, as suggested by the maintainer.

@pamtbaau, thank you for coming to my aid yet again! Your changes got the plugin to work as smoothly as before – fantastic!

Not getting any output for dump($event) is a pity and a problem for people like me who very usually dump their way through code, but in this case, I’ll create a pull request either way as your improvements are all that was needed. Thanks again!

@Netzhexe, Issue has been fixed and will soon be released. See changelog for upcomming release v1.7.0-rc.16