kongondo

Module: RuntimeMarkup Fieldtype & Inputfield

Recommended Posts

i have one type of button that submits via ajax so does all of the processing without opening a new window; some of my more primitive versions just open a new window to run the action...

  • Like 1

Share this post


Link to post
Share on other sites

yeah, i also went with ajax for now. but it's strange that it worked before... and it seems more complicated now than necessary and with pw that's usually the feeling when something is wrong :) 

Share this post


Link to post
Share on other sites
1 hour ago, bernhard said:

so what changed since your example here? and how could i detect clicks on buttons?

 

Nothing has changed. It works just fine. If you use $input->post in your 'my-file.php', it will work as expected. If used directly in 'Copy Paste' code, it won't.

 

1 hour ago, bernhard said:

and how could i detect clicks on buttons?

For buttons, that would have to be JS from what I see. E.g., dump this after if($copy) {} in my example in the quoted post:

echo '<pre>';
print_r($input->post);
echo '</pre>';
exit;

You will see all the POST values (but no 'submit_save' there; I guess the post is submitted in some other way) including the 'Create Copy' button, body fields, etc. So, to detect submit button, you could do the following in your 'my-file.php':

if($input->post->title) {
// blah blah
}

 

Share this post


Link to post
Share on other sites

Hi Kongondo

Thanks for this great module! I use it on several templates and in the frontend everything works fine. I use it mainly to concatenate text… Now i have a firstname and lastname field on the user that i combine into a single runtimemarkup field "fullname" – it displays correctly in the frontend but the backend profile page does not display the computed value: return $page->firstname." ".$page->lastname;

Any ideas on why that could happen?

Share this post


Link to post
Share on other sites

@noelboss - have you tried using TracyDebugger yet? You could get that going and then troubleshoot the contents of the $page in the profile editor; you may also be able to see warnings and errors when using Tracy. Using it is pretty much required if you are doing any serious dev work in the backend.

  • Like 3

Share this post


Link to post
Share on other sites
7 hours ago, noelboss said:

Hi Kongondo

Thanks for this great module! I use it on several templates and in the frontend everything works fine. I use it mainly to concatenate text… Now i have a firstname and lastname field on the user that i combine into a single runtimemarkup field "fullname" – it displays correctly in the frontend but the backend profile page does not display the computed value: return $page->firstname." ".$page->lastname;

Any ideas on why that could happen?

Welcome to the forums. Glad you find the module useful.

Regarding your question, it's hard to tell without seeing some code. Are you using the field directly in the ProcessWire user template or you have some other pseudo page for users?

Share this post


Link to post
Share on other sites
On 06/09/2017 at 4:57 AM, kongondo said:

Are you using the field directly in the ProcessWire user template or you have some other pseudo page for users?

I'm guessing he is talking about the profile edit interface (ProcessProfile). There are a couple of places where the module assumes/requires ProcessPageEdit.

Share this post


Link to post
Share on other sites

Hi all. 

I am intending to ONLY support ProcessWire 3.x starting from the next version of this module. Please have a read here and let me know what you think. Thanks.

Share this post


Link to post
Share on other sites

Is it possible to use field collapsed status with this - since the module itself doesn't have a value that can trigger 'populated' status (?)... I'm using a lot of these on a page , but need keep them all open...

Share this post


Link to post
Share on other sites
On 01/12/2017 at 3:35 PM, Macrura said:

but need keep them all open...

Aren't they all staying open?

 

On 01/12/2017 at 3:35 PM, Macrura said:

Is it possible to use field collapsed status

Will investigate. 

Share this post


Link to post
Share on other sites

oops, mis-typed, i meant keep closed when blank; they do stay open if set to open.

I guess maybe i need to make sure my code returns empty for this to work; will check again.

Share this post


Link to post
Share on other sites

Can't believe I discovered this awesome module only recently... I mean, it's over 2 years old now already :o

Here's another use-case: 

 

  • Like 3

Share this post


Link to post
Share on other sites

I'm getting a strange glitch with this.  I'm on PW 3.0.9.  If I put my code directly into the field it works fine, but if I try to use an external file using return ProcessWire\wireRenderFile('runtime.php');  the page is always returned as page id 10, not the the page I'm on.   

Not tragic as I can put the code directly in the field but would be better to have it external if possible.

Thanks!

Heather

Share this post


Link to post
Share on other sites

Hi @hezmann

33 minutes ago, hezmann said:

I'm getting a strange glitch with this.  I'm on PW 3.0.9.  If I put my code directly into the field it works fine, but if I try to use an external file using return ProcessWire\wireRenderFile('runtime.php');  the page is always returned as page id 10, not the the page I'm on.   

That's because the code (in the field) is locally scoped so that $page refers to the page you are editing. However, if using wireRenderFile(), you need to get the page being edited yourself. When editing a page, the page (named) edit is what ProcessWire assigns to $page. The page edit has the id 10. So, what you need is code like below to get the page being edited:

$currentPage = '';
$process = wire('process'); 
if($process && $process->className() == 'ProcessPageEdit') $currentPage = $process->getPage();
if(!$currentPage) return;
// if you get here $currentPage is the page being edited

More in this post. Sorry, this should be in the docs. I will update the docs at some point (when I get the time).

Hope this helps.

Edited by kongondo
  • Like 1

Share this post


Link to post
Share on other sites

Is it possible to use this field on a custom user template ? 

I'm trying but if I just put "return $page->id" in the field I have an error  "Undefined variable: page" ...
If I try with a external file, I have $page but It's the "users" parent page and not the user I'm editing 

:( 

Share this post


Link to post
Share on other sites
8 hours ago, Sonia Margollé said:

Is it possible to use this field on a custom user template ? 

I haven't tried, sorry. I'll check when I get a bit of time. I've never used the custom user template feature so will have to do a bit of reading first. Have you tried with wire('page')? This post might also be handy (i.e. establishing process context)

 

Share this post


Link to post
Share on other sites

Hey @kongondo - would you consider adding this to the module please?

$f = $this->modules->isInstalled('InputfieldAceExtended') ? $this->modules->get('InputfieldAceExtended') : $this->modules->get('InputfieldTextarea');

in the ___getConfigInputfields method?

Thanks!

Share this post


Link to post
Share on other sites

It would also be good to have:

$f->rows = 20;

or even make it configurable.

One other thing - because InputfieldAceExtended is not in inline mode, you need <?php to force code highlighting, but your module doesn't allow this. Would you mind stripping out any <?php that is added so that this works? This should do it:

$str = eval(str_replace('<?php', '', $this->runtimeFields));
$str = eval(str_replace('<?php', '', $field->runtimeFields));

One each for FieldtypeRuntimMarkup and InputfieldRuntimeMarkup.

Thanks!

Share this post


Link to post
Share on other sites

;)

But still I think using your IDE is the best option for larger code snippets... No need for ACE then. I'm still unsing my render replacement hook

 

Share this post


Link to post
Share on other sites
2 minutes ago, bernhard said:

But still I think using your IDE is the best option for larger code snippets... No need for ACE then

I still think it's nice to have even for short snippets, but maybe that's just me? If nothing else it lets you actually use the tab key to indent which you can't do in a normal textarea.

Share this post


Link to post
Share on other sites

Sure it's nice :) I think this was lost in translation :) I meant if you are using the IDE you don't need ACE, but of course it's nice to have it in the backend. The Tracy Console is a perfect example. I'm using ACE myself in several projects

  • Like 1

Share this post


Link to post
Share on other sites

Sorry @kongondo - me again :)

I am noticing that the renderMarkup() method is called many times on the currently edited page and it's also called on page reference fields on the page being edited. This makes for a lot of calls to this method that don't seem necessary as far as I can tell. Do you think this can be improved?

As an example, I put: bd($page->id); at the top of that method and saw this:

image.thumb.png.37bb806099db03174abb5d1ffeea5e9a.png

I am currently editing page 1100, but there are a few page reference fields which are also showing up in that list.

Thanks for taking a look!

 

 

  • Like 2

Share this post


Link to post
Share on other sites

Thanks @adrian. I'll look at these when I upgrade the module to PW3.x-support only. I have no ETA though, I'm afraid.

  • Like 1

Share this post


Link to post
Share on other sites

Hey @kongondo - seems like it's all because of the ___wakeupValue and ___sleepValue methods. Is there any reason they can't just return true, rather than returning $this->renderMarkup($page, $field); ?

Thanks!

  • Like 1

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By bernhard
      @Sergio asked about the pdf creation process in the showcase thread about my 360° feedback/survey tool and so I went ahead and set my little pdf helper module to public:
       
      Download & Docs: https://gitlab.com/baumrock/RockPdf
       
      You can combine it easily with RockReplacer: 
       
    • By Soma
      LogMaintenance
      A simple ProcessWire module to give some maintenance control over log files. I found myself often having lots of log files for different things that can grow more or less quickly to a size where they can be difficult to maintain. The built in Logger of PW does a good job of giving you the possibility to delete or prune logs. But it has to be done manually and sometimes a log grows into millions of lines, which makes it often impossible to even prune it as it's too large.
      LogMaintenance uses LazyCron to run the maintenance task and there's several settings you can setup on a global or per log basis.
      Archive: will create zip files for each log file in logs/archive/ folder and add the log each time the maintenance is run to a subfolder containing the datetime.
      Lines: keeps logs to a certain number of lines 
      Days: keeps the log to a certain number of days
      Bytes: keeps the log to a certain amount of bytes
      Each setting is checked from top down, the first setting to contain something is used. So if you check the "Archive" option, all other settings are ignored and logs are archived everytime the LazyCron is executed. If you want to keep your logs to a certain amount of bytes just leave all other settings to 0 or blank.
      Per Log Settings
      There's a textarea that you can use to setup a config for a specific log file one per line. All the logs you define here ignore the global settings above. The syntax for the settings is:
      logname:[archive]:[lines]:[days]:[bytes] 
      errors:1:0:0:0 // would archive the errors log messages:0:10000:0:0 // will prune the errors log to 10000 lines  
      The module can be found on github for you to check out. It's still fresh and I'm currently testing.
      https://github.com/somatonic/LogMaintenance
    • By teppo
      Fieldtype Page IDs is a third party Fieldtype that, simply put, stores Page references as integers (Page IDs).
      This fieldtype was built as a quick and dirty workaround for Page Reference fields' inability handle self-references due to circular reference issues. A project I've been working on for a while now includes a combination of RepeaterMatrix content blocks and tagging/categorization system that would've resulted in a lot of duplicate pages (and plenty of unnecessary manual work for content editors) had I used built-in Page Reference fields, and thus a new Fieldtype felt like the most sensible approach.
      Fieldtype Page IDs was designed to be loosely compatible with Page References in order to make conversions between the two feasible, but it is quite limited feature wise:
      largely due to the fact that stored values are actually just integers with no connection to Pages whatsoever some advanced selectors and related features are not supported, and page values can't be directly accessed configuration settings are limited to the bare essentials (selector string and Inputfield class) only a handful of Inputfields (AsmSelect, Checkboxes, Text) are (currently) supported Anyway, in case you need to store Page IDs (and Page IDs only) and are happy with the limitations mentioned above, feel free to give this Fieldtype a try. It has been working fine for me in one particular project, but hasn't been tested that much, so please tread carefully – and let me know if you run into any issues.
      GitHub repository: https://github.com/teppokoivula/FieldtypePageIDs
      Modules directory: https://modules.processwire.com/modules/fieldtype-page-ids/
    • By daniels
      This is a lightweight alternative to other newsletter & newsletter-subscription modules.
      You can find the Module in the Modules directory and on Github
      It can subscribe, update, unsubscribe & delete a user in a list in Mailchimp with MailChimp API 3.0. It does not provide any forms or validation, so you can feel free to use your own. To protect your users, it does not save any user data in logs or sends them to an admin.
      This module fits your needs if you...
      ...use Mailchimp as your newsletter / email-automation tool ...want to let users subscribe to your newsletter on your website ...want to use your own form, validation and messages (with or without the wire forms) ...don't want any personal user data saved in any way in your ProcessWire environment (cf. EU data regulation terms) ...like to subscribe, update, unsubscribe or delete users to/from different lists ...like the Mailchimp UI for creating / sending / reviewing email campaigns *I have only tested it with PHP 7.x so far, so use on owners risk
      EDIT:
      I've updated the module to 0.0.4. I removed the instructions from this forum, so I don't have to maintain it on multiple places. Just checkout the readme on github 🙂
      If you have questions or like to contribute, just post a reply or create an issue or pr on github. 
    • By bernhard
      WHY?
      This module was built to fill the gap between simple $pages->find() operations and complex SQL queries.
      The problem with $pages->find() is that it loads all pages into memory and that can be a problem when querying multiple thousands of pages. Even $pages->findMany() loads all pages into memory and therefore is a lot slower than regular SQL.
      The problem with SQL on the other hand is, that the queries are quite complex to build. All fields are separate tables, some repeatable fields use multiple rows for their content that belong to only one single page, you always need to check for the page status (which is not necessary on regular find() operations and therefore nobody is used to that).
      In short: It is far too much work to efficiently and easily get an array of data based on PW pages and fields and I need that a lot for my RockGrid module to build all kinds of tabular data.

      Basic Usage

       
      Docs & Download
      https://modules.processwire.com/modules/rock-finder/
      https://gitlab.com/baumrock/RockFinder/tree/master
       
      Changelog
      180528, v1.0.4 add custom select statement option 180516 change sql query method, bump version to 1.0.0 180515 multilang bugfix 180513 beta release <180513 preview/discussion took place here: https://processwire.com/talk/topic/18983-rocksqlfinder-highly-efficient-and-flexible-sql-finder-module/