Skip to content

Instantly share code, notes, and snippets.

@bwente
Created February 17, 2023 19:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bwente/b9bd7fc1e17a5cb63d65241d557def75 to your computer and use it in GitHub Desktop.
Save bwente/b9bd7fc1e17a5cb63d65241d557def75 to your computer and use it in GitHub Desktop.
staticPdfResourceFixer [plug-in]
<?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