Jump to content

Fieldtype Runtime Only


Robin S
 Share

Recommended Posts

Just now, virtualgadjo said:

i went for the first solution

if(!$input->is('post')) { // works fine too :)

I updated my example because $input->is('post') is probably a bit too broad. It might be fine for your case but if you want to show the RuntimeOnly field value as a column in a Lister then $input->is('post') is true when the Lister results get AJAX-loaded according to the filter form values. So checking for the Page Edit submit button value with if(!$input->post('submit_save')) is probably better.

  • Thanks 1
Link to comment
Share on other sites

  • 1 year later...

Hi,

you'll probably find this a little funny but now i'm trying to reproduce your fieldtype abilities but saving data to the database to make it "indexxable" by teppo great search engine as it will allow me to get datas from any database i need even an external one and save it as a field content with or without formatting

thanks again for this great module i porbably play a bit too much with ?

have a nice day

  • Like 1
Link to comment
Share on other sites

  • 2 months later...

Hi @Robin S. The module is really neat and I've forked and hacked it a couple of times to simplify it for use in my own modules (with accreditation!). I came across an interesting feature of PW recently regarding Page Table fields. If I create a Runtime field and include it as a column in a PageTable field, I do not need to include it in any of the templates managed by the Page Table field (assuming it is only needed to display in the Page Table field). This is a really handy way of providing useful information in the Page Table listing and saves a bit of effort, especially if there are lots of templates.

However, the js and css is not then automatically picked up. I fixed this by moving the code in InputfieldRuntimeOnly::renderReady() to FieldtypeRuntimeOnly::renderMarkup() and also moving getPath() and getUrl(). Everything seems to work like this in both the normal (field in template) and novel use. I wondered whether there was a particular reason for putting it in renderReady(), as it would seem more usable in renderMarkup()?

Link to comment
Share on other sites

On 1/18/2024 at 5:00 AM, MarkE said:

I wondered whether there was a particular reason for putting it in renderReady(), as it would seem more usable in renderMarkup()?

Inputfield::renderReady() is the correct core method for ensuring that JS and CSS dependencies for the inputfield get loaded in all circumstances - see the phpDoc comments for the method. It needs to be this method so that dependencies are loaded when the inputfield is within an AJAX-loaded repeater, for example. So I don't want to risk introducing problems by changing this for what sounds like an unusual usage of the module.

But you could use a hook to call InputfieldRuntimeOnly::renderReady() after the method that calls FieldtypeRuntimeOnly::renderMarkup().

$wire->addHookAfter('FieldtypeRuntimeOnly::wakeupValue', function(HookEvent $event) {
	/** @var Page $page */
	$page = $event->arguments(0);
	/** @var Field $field */
	$field = $event->arguments(1);
	$inputfield = $field->getInputfield($page);
	$inputfield->renderReady();
});

 

  • Like 2
Link to comment
Share on other sites

7 hours ago, Robin S said:

But you could use a hook to call InputfieldRuntimeOnly::renderReady() after the method that calls FieldtypeRuntimeOnly::renderMarkup().

Hmm. Thanks @Robin S. I had already tried something similar with no success. I tried your hook, but it doesn't seem to get triggered in the particular circumstances I described (i.e. when the field is not added to the templates, just included as a column).

UPDATE: However, $wire->addHookBefore('FieldtypeRuntimeOnly::markupValue', function(HookEvent $event) seems to do the trick

In fact, since I was using a forked hacked version of your module anyway, it was simpler to add 

			$inputfield = $field->getInputfield($page);
			$inputfield->renderReady();

in markupValue() - just before return $this->renderMarkup($page, $field); ?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...