Created
February 17, 2023 19:06
-
-
Save bwente/b9bd7fc1e17a5cb63d65241d557def75 to your computer and use it in GitHub Desktop.
staticPdfResourceFixer [plug-in]
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
<?php | |
/* | |
*/ | |
switch ($modx->event->name) { | |
case 'OnBeforeDocFormSave': | |
if ( $mode == modSystemEvent::MODE_NEW ) { | |
// stuff to do before saving a new resource | |
// this example checks the parent document, and updates various resource fields | |
if ( $resource->get('contentType') == 'application/pdf' ) { | |
$staticResourcePath = $resource->get('content'); | |
$resource->set('menutitle', $staticResourcePath); | |
$resource->set('cacheable', 0); | |
$resource->save(); | |
} | |
} else if ( $mode == modSystemEvent::MODE_UPD ) { | |
// stuff to do before updating a resource | |
} | |
break; | |
case 'OnDocFormSave': | |
if ( $mode == modSystemEvent::MODE_UPD ) { | |
// stuff to do after updating a resource | |
if ( $resource->get('contentType') == 'application/pdf' ) { | |
$staticResourcePath = $resource->get('content'); | |
$resource->set('menutitle', $staticResourcePath); | |
$resource->set('cacheable', 0); | |
$resource->save(); | |
// | |
} | |
} | |
break; | |
default: | |
break; | |
} | |
return; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment