Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2021-10-25 12:03:10

THE BLUE DRAGON
Member
From: Israel
Registered: 2007-11-16
Posts: 622
Website

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

#2 2021-10-25 12:11:02

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,633
Website

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

#3 2021-10-25 12:29:21

THE BLUE DRAGON
Member
From: Israel
Registered: 2007-11-16
Posts: 622
Website

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

#4 2021-10-25 19:12:55

etc
Developer
Registered: 2010-11-11
Posts: 5,093
Website GitHub

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

#5 2024-06-22 23:24:43

THE BLUE DRAGON
Member
From: Israel
Registered: 2007-11-16
Posts: 622
Website

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.

There are probably better ways of doing this, for example:
  • Removing the selectors you don’t want from the $selector array inside the updateVolatilePartials 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, from PARTIAL_VOLATILE to PARTIAL_VOLATILE_VALUE
    but since it is now already after 2AM then I will give it a try tomorrow.

Offline

Board footer

Powered by FluxBB