Last active
March 9, 2019 22:05
-
-
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.
This file contains hidden or 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 | |
// 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