Quote from: ChuckTrukk at Feb 02, 2009, 11:25 AM
How would I retrieve the placeholders in a page?
would I use something like $tags = $parser->collectElementTags();
Yes, basically using the process the current QuickEdit uses, which is the OnParseDocument event. This event in Revolution (unlike 0.9.x) executes as each level of tags are processed.
The new parser is a special "service" object of modX, and once loaded, is available as $modx->parser. Then you can use collectElementTags to grab all the tags in the content (note it will return the number of tags found, not including nested tags) and do what you need to with them:
<?php
/* create arrays to hold your tags and your replacement targets */
$tags = array();
$targets = array();
/* collect the tags found in $modx->documentOutput into your tag array */
$tagCount = $modx->parser->collectElementTags($modx->documentOutput, $tags);
if ($tagCount) {
/* you could just add logic to replace the tags then with your controls
by setting a property for the plugin that contains a prefix and suffix template */
foreach ($tags as $tag) {
/* TODO: here you can inspect the tag and determine if it should be replaced */
$targets[$tag[0]] = $prefix . $tag[0] . $suffix;
}
if (!empty($targets) $modx->parser->mergeTagOutput($targets, $modx->documentOutput);
}
?>
Be aware this needs to be as efficient as possible, as this event executes every time a piece of content is parsed for tags, including tags that are nested in other tags, and when processed tags return additional tags. On average this will be executed 10 to 20x more frequently than QuickEdit did in 0.9.x.
Also, you will NEVER want the page to be cached when rendered with QuickEdit controls! A switch statement in the above plugin to listen for the calling event and simply disable caching for that view would work, e.g.
<?php
switch ($modx->event->name) {
case 'OnParseDocument':
/* put code from above here */
break;
case 'OnWebPagePrerender':
$modx->config['cache_resource'] = false;
break;
}
?>