Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Prevents custom fields from refresh on publish/save
Hi, currently when you click on the publish or save buttons on the Write-page it refresh the custom fields DOM elements and remove any HTML modifications that has done to them, for example it removes the “bot_image_upload” plugin UI and returns the custom fields to normal.
Unlike the custom fields, the publish/save functions does not change the Title and Body fields HTML modifications, so this seems to happen only to the custom fields.
So I would like to know why is it like that, is it a bug or is it a feature, and how can I disable it in the code please?
Offline
Re: Prevents custom fields from refresh on publish/save
Yes, the custom fields get refreshed by the async save and that can cause custom write panel plugins (especially older ones) to lose their place. If you reload the page (via the browser url bar), the layout should return to usual. I think this needs solving in “bot_image_upload”. I know I struggled with this with glz_custom_fields / bot_write_tab_customize and only partially resolved it.
BTW: you might want to look at com_article_image as a potential replacement for bot_image_upload.
TXP Builders – finely-crafted code, design and txp
Offline
Re: Prevents custom fields from refresh on publish/save
jakob wrote #331860:
I think this needs solving in “bot_image_upload”.
Thank you, is there a callback function that I can listen to and then refresh the plugin or even the whole page please?
Offline
Re: Prevents custom fields from refresh on publish/save
THE BLUE DRAGON wrote #331861:
Thank you, is there a callback function that I can listen to and then refresh the plugin or even the whole page please?
Hi,
no warranty, but you can try to inject the following code on the admin side:
register_callback(function() {
global $app_mode;
$app_mode = null;
}, 'article', '', 1);
Offline
Re: Prevents custom fields from refresh on publish/save
Hi, after spending hours searching where is it in the core code, I have finally found how to do it in the updateVolatilePartials
function inside the txplib_admin.php
file.
You can change the foreach
loop and check for each case (selector) to decide whether or not it to be refreshed/replacedwith.
Here’s the current list of selectors (TXP v4.8.8) to choose from:
(you can find the list of them in the txp_article.php
file in the article_edit
function, these with mode PARTIAL_VOLATILE
)
- title
- div.author
- #txp-article-actions
- nav.nav-tertiary
- #txp-container-status
- #publish-datetime-group
- #expires-datetime-group
- #write-comments
- #txp-image-group .txp-container
- #txp-custom-field-group-content .txp-container
- #txp-recent-group-content .txp-container
So you can change this:
foreach ($selector as $i => $sel) {
$response[] = '$("'.$sel.'").replaceWith($html.find("'.$fragment[$i].'"))';
}
To something like this:
foreach ($selector as $i => $sel) {
switch ($sel) {
case 'div.author': break;
case 'nav.nav-tertiary': break;
case '#txp-container-status': break;
case '#publish-datetime-group': break;
case '#expires-datetime-group': break;
case '#write-comments': break;
case '#txp-image-group .txp-container': break;
case '#txp-custom-field-group-content .txp-container': break;
case '#txp-recent-group-content .txp-container': break;
default:
$response[] = '$("'.$sel.'").replaceWith($html.find("'.$fragment[$i].'"))';
}
}
So in the example above, I only keep the title
and #txp-article-actions
selectors but not the rest.
And the reason to state all the others instead of only these that I do want, it is because this function updateVolatilePartials
is NOT only in use to update/refresh elements in the article/write tab, but also for “pages”, “forms”, and “styles” (txp_page.php
, txp_form.txp
, txp_css.txp
) so make sure you do not change these.
- Removing the selectors you don’t want from the
$selector
array inside theupdateVolatilePartials
function and then only loop the rest. - To send another parameter to the
updateVolatilePartials
function with the page type (article/page/form/style). - Or probably just to change the mode of each selector in the
txp_article.php
file, fromPARTIAL_VOLATILE
toPARTIAL_VOLATILE_VALUE
but since it is now already after 2AM then I will give it a try tomorrow.
Offline