Skip to content

Instantly share code, notes, and snippets.

@pmfx
Last active March 9, 2019 22:05
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 pmfx/fcb50c22cb83aa29c63986ce88c7db3f to your computer and use it in GitHub Desktop.
Save pmfx/fcb50c22cb83aa29c63986ce88c7db3f to your computer and use it in GitHub Desktop.
Saves a copy of PageBuilder values in content field of the site_content table. Useful for search or filtering with other snippets.
<?php
// PageBuilder_saveContent
// Saves a copy of PageBuilder values in content field of the site_content table.
// Event: OnDocFormSave
// https://gist.github.com/pmfx/fcb50c22cb83aa29c63986ce88c7db3f
$e = &$modx->Event;
if ( $e->name == "OnDocFormSave" ) {
if ( !empty($_POST['contentblocks']) && !empty($_POST['id']) ) {
$id = (int)$_POST['id'];
$table = $modx->getFullTableName('site_content');
$pb_content = '';
foreach ($_POST['contentblocks'] as $container => $blocks) {
if (is_array($blocks)) {
foreach ($blocks as $index => $row) {
$pb_content .= $modx->db->escape($row['values']);
}
}
}
$fields = array('content' => $pb_content);
$result = $modx->db->update($fields, $table, 'id = "' . $id . '"');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment