Last active
August 29, 2015 14:01
-
-
Save christianseel/557a1e0f2a1f502ce1c5 to your computer and use it in GitHub Desktop.
Add this as a plugin (OnDocFormSave). Saves the first MoreGallery image into a TV (could be a hidden one) for quicker access.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Get the images | |
$corePath = $modx->getOption('moregallery.core_path', null, $modx->getOption('core_path') . 'components/moregallery/'); | |
$moreGallery = $modx->getService('moregallery', 'moreGallery', $corePath . 'model/moregallery/'); | |
$c = $modx->newQuery('mgImage'); | |
$c->where(array( | |
'resource' => $resource->get('id'), | |
)); | |
$c->sortby('sortorder', 'ASC'); | |
$c->limit('1'); | |
$image = $modx->getObject('mgImage', $c); | |
if($image){ | |
$image = $image->toArray(); | |
$resource->setTVValue('ref-image', $image['file_url']); | |
$resource->save(); | |
} |
Good point! Added it!
As MoreGallery is loaded as an extension package, you shouldn't need those first two lines ($corePath = .. and $moreGallery = ...)... very cool tho!
I've added optional output of crop images to this plugin: https://gist.github.com/pepebe/ad0217f0e8cb0ee870cb
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice plugin Very helpful.
I think you should check if getObject in line 11 returns something.