Last active
December 19, 2023 12:48
Get the ID of the "Root Resource", aka "Ultimate Parent", with slightly different feature set.
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 | |
/* | |
* @author @sepiariver | |
* | |
* GPL license, no warranties, no liability, etc. | |
* | |
* USAGE EXAMPLE: | |
* [[rootResource? &toPlaceholder=`root_resource`]] | |
* //followed by something like | |
* [[getResources? &parents=`[[+root_resource]]` ... ]] | |
* | |
*/ | |
$id = $modx->getOption('id', $scriptProperties, $modx->resource->get('id')); | |
$toPlaceholder = $modx->getOption('toPlaceholder', $scriptProperties, ''); | |
$pids = array_reverse($modx->getParentIds($id)); | |
$output = (isset($pids[1]) && !empty($pids[1])) ? $pids[1] : $id; | |
if (empty($toPlaceholder)) return $output; | |
$modx->setPlaceholder($toPlaceholder, $output); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment