Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Plugins

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

admin plugins

Solved by pamtbaau View solution

Started by Anna 6 years ago · 3 replies · 853 views
6 years ago

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:

PHP
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!

6 years ago Solution

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

  • Import the new Flex page object
    PHP
    use Grav\Common\Flex\Types\Pages\PageObject;
    
  • When a flex page is being saved, $event contains 'page' instead of 'object'

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

last edited 08/23/20 by pamtbaau
6 years ago

@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!

6 years ago

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

Suggested topics

Topic Participants Replies Views Activity
Plugins · by Rene, 1 week ago
2 75 1 week ago
Plugins · by Xavier, 4 weeks ago
2 81 4 weeks ago
Plugins · by Luka Prinčič, 7 years ago
3 1208 1 month ago
Plugins · by Sebastian van de Meer, 1 month ago
1 74 1 month ago
Plugins · by PIERROT Alain, 2 months ago
3 99 2 months ago