I can think of several things to try. First, try just leaving NewsPublisher alone and putting a snippet with this code above the NP snippet tag:
<?php
$ph = ''; /* your computed pagetitle here */
$modx->setPlaceholder('np.pagetitle', $ph);
If that doesn't work, I think what you're doing could work, but I think there's an easier way (see below). To do it your way, the part you're inserting for the pagetitle should look like a modified version of this (I would make it readonly rather than hidden -- at least during development):
<div id="np-pagetitle-container" class="np-text">
[[+np.error_pagetitle]]]]
<label class="fieldlabel" for="np-pagetitle" title="[[+npx.help]]">[[+npx.caption]]: </label>
<input name="pagetitle" class="text" id="np-pagetitle" readonly="readonly" type="text" value="[[+np.pagetitle]]" maxlength="[[+npx.maxlength]]" />
</div>
I'm guessing here, so some of the above may not be quite right, but then I would put a snippet above the NewsPublisher snippet to set the np.pagetitle placeholder.
<?php
$ph = ''; /* your computed pagetitle here */
$modx->setPlaceholder('np.pagetitle', $ph);
Another, possibly easier and more reliable method that wouldn't require you to customize NewsPublisher at all would be to create a plugin attached to OnDocFormSave (or possibly OnBeforeDocFormSave).
<?php
/* only execute on new docs */
if ($mode != modSystemEvent::MODE_NEW) {
return '';
}
/* need a test here to make sure it's a NewsPublisher doc, probably based on the parent */
if ($resource->get('parent') != 12) {
return '';
}
/* make sure pagetitle was empty */
if ($resource->get('pagetitle') != $modx->lexicon('resource_untitled') {
return '';;
}
$pt = ''; /* your computed pagetitle here using $resource->getTVValue('ProductLine') etc. */
$resource->set('pagetitle', $pt);
$resource->save();
You would have to make pagetitle not required by setting the &required property and leaving out the pagetitle. I haven't tested any of this, but I think either method could work -- I would try the little snippet at the top first, then the plugin. Let me know how it works out.
Someday, NewsPublisher will have postHooks, but probably not any time soon.
[ed. note: BobRay last edited this post 11 years, 1 month ago.]