Jump to content
kongondo

Module: RuntimeMarkup Fieldtype & Inputfield

Recommended Posts

Hey @kongondo - these changes seem to work well and prevent any unnecessary re-rendering of the output.

In the fieldtype, I change these three methods to return true.

    public function ___sleepValue(Page $page, Field $field, $value) {
        //return $this->renderMarkup($page, $field);
        return true;
    }

    public function getLoadQuery(Field $field, DatabaseQuerySelect $query) {
        // prevent loading from DB
        return $query;
    }

    public function ___loadPageField(Page $page, Field $field) {
        // generate value at runtime rather than loading from DB
        //return $this->renderMarkup($page, $field);
        return true;
    }

And in the inputfield I replace the ___render() method with the following which returns the wakeup value without re-rendering.

    public function ___render() {

        //if code field is empty return early
        if(!$this->runtimeFields) return;

        //so that $page and $pages are locally scoped to the eval
        $process = $this->wire('process');
        if($process && ($process->className() == 'ProcessPageEdit' || $process->className() == 'ProcessUser')) {
            $page = $process->getPage();
            return $page->{$this->name};
        }
        else {
            return;
        }

    }

Let me know if you have any questions / comments about this approach.

Thanks again for an invaluable module!

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites
On 2/13/2019 at 6:20 PM, adrian said:

Let me know if you have any questions / comments about this approach.

Thanks @adrian. I'll have a look (but not sure when :)). I'm swamped all around!

 

If it's not too much to ask, could you please create an issue and reference your post above? Thanks.

Edited by kongondo

Share this post


Link to post
Share on other sites

I've been using this field type for a while and very good it is too, but now I am scratching my head:

I have a runtime_markup field ('runtime_markup_expiryDate') with PHP as follows

return ($page->parent->name == 'memberships' and $page->latestSubscription()->id) ? date('d/m/Y', $page->latestSubscription()->subsEndDate) : 'Non-subscriber';

This works well in the back-end, but gives the wrong result in the API. If I retrieve the field in the API, it just gives 01/01/1970.

However, if I remove the formatting in the PHP, thus:

return ($page->parent->name == 'memberships' and $page->latestSubscription()->id) ? $page->latestSubscription()->subsEndDate : 'Non-subscriber';

it works correctly in the API (gives the right date, e.g. 30/09/2019) but obviously just gives the integer in the back end (e.g. 1569798000). The curious thing is that, in this case I can't work out where the formatting is applied in the API (which might be related to the cause of the problem)

What is going on? Any suggestions for a fix or work-round?

Thanks.

Share this post


Link to post
Share on other sites
date('d/m/Y', $page->latestSubscription()->subsEndDate) // change this
date('d/m/Y', $page->latestSubscription()->getUnformatted('subsEndDate')) // to this

 

  • Like 3

Share this post


Link to post
Share on other sites

Update version 006 - 11 May 2019

Finally got a bit of time to work on this module.

Changelog

  • Namespacing: ProcessWire 3.x Support only from now on.
  • Removed the module's CSS and JS files. They are unnecessary.
  •  Switched to $files->render() instead of wireRenderFile().
  • Option to check for and optionally use InputfieldAceExtended for code highlighting in the PHP custom code textarea. Thanks to @adrian , @diogo and others who suggested this.
  • Option to specify number of rows for the PHP custom code textarea (@note: for some reason, it's not working with Ace Extended. It does work with plain textarea).
  • Removed the option (in field settings) to search for files to render under /site/modules/FieldTypeRuntimeMarkup/ as these could get overwritten during upgrades.
  • Refactored code to prevent unnecessary re-rendering of output, thanks @adrian
  • Render PHP file mode is now supported for frontend use as well, thanks @Noel Boss
  • Changed license to MIT.

Please note this is the new master and is available in the modules directory.

Screenshots

rtm_005_code_highlight_and_rows_config.thumb.jpg.2a390851d3dd63540b8828b87ed62c37.jpg

Over to you @bernhard 😀.

 

Edited by kongondo
  • Like 6

Share this post


Link to post
Share on other sites

Btw, mainly for @bernhard and @adrian who have previously looked at RTM code, InputfieldRuntimeMarkup now behaves similar to many inputfields in that it gets its values from the Fieldtype's wakeupValue(), i.e. from $this->attr('value').  The previous implementation seemed a bit unclean to me when I looked at it recently. We had the inputfield doing its own eval() or wireRenderFile(). Now I've moved everything to FieldtypeRuntimeMarkup plus added a small helper class in there to handle such things. All the inputfield does now is serve values, as inputfields are meant to do.

  • Like 3

Share this post


Link to post
Share on other sites

Hello @kongondo

I updated a site to v.0.0.6 and now when trying to edit a – seemingly unrelated – TextareaLanguage field by using the field overwrite editor modal of a template I get this:

Fatal Error: Uncaught Error: Class 'ProcessWire\RuntimeMarkupUtilities' not found in .../site/modules/FieldtypeRuntimeMarkup/InputfieldRuntimeMarkup.module:68
Stack trace:
#0 .../wire/core/Modules.php(624): ProcessWire\InputfieldRuntimeMarkup->init()
#1 .../wire/core/Modules.php(1336): ProcessWire\Modules->initModule(Object(ProcessWire\InputfieldRuntimeMarkup), Array)
#2 .../wire/core/Modules.php(1193): ProcessWire\Modules->getModule('InputfieldRunti...')
#3 .../wire/core/Modules.php(1566): ProcessWire\Modules->get('InputfieldRunti...')
#4 .../wire/modules/Fieldtype/FieldtypeTextareaHelper.php(40): ProcessWire\Modules->find('className^=Inpu...')
#5 .../wire/modules/Fieldtype/FieldtypeTextarea.module(338): ProcessWire\FieldtypeTextareaHelper->getConfigInputfields(Object(Proce (line 68 of .../site/modules/FieldtypeRuntimeMarkup/InputfieldRuntimeMarkup.module)

This error message was shown because: site is in debug mode. ($config->debug = true; => /site/config.php). Administrator has been notified. Error has been logged.

I tried uninstalling the module (because the site does not use it yet anyway, meaning there is no field using RuntimeMarkup) and when I click on the uninstall button I also get: 

Class 'ProcessWire\RuntimeMarkupUtilities' not found 

However, if I create a RuntimeMarkup field then the error goes away in both cases described above. It looks like the case when there is no RuntimeMarkup filed in the system is not taken into account. So with a RuntimeMarkup field created, I could uninstall the module as the fatal error did not crop up in that case.

Also note that I find it strange that both FieldtypeRuntimeMarkup and InputfieldRuntimeMarkup show up as RuntimeMarkup in the module list, see the screenshots:

Spoiler

RuntimeMarkup-module-shots.thumb.gif.4f86c5662891c2fe7e6f38c6953bb6ff.gif

 

Edited by szabesz
Also see my next post below.

Share this post


Link to post
Share on other sites
21 hours ago, szabesz said:

Also note that I find it strange that both FieldtypeRuntimeMarkup and InputfieldRuntimeMarkup show up as RuntimeMarkup in the module list, see the screenshots:

Sorry, rookie mistake on my part :-). I had them both with identical titles. Corrected in 007.

21 hours ago, szabesz said:

I updated a site to v.0.0.6 and now when trying to edit a – seemingly unrelated – TextareaLanguage field by using the field overwrite editor modal of a template I get this:

Hmm. That's very strange. By 'overwrite editor modal', do you mean the one where you can overwrite a field's 'original' label, description, notes, etc for a specific template?

Are you able give me more details please?

  1. Which field values did you try to edit?
  2. Did the error crop up after saving or as soon as you opened the modal?
  3. ProcessWire version

Thanks.

  • Like 1

Share this post


Link to post
Share on other sites
11 minutes ago, kongondo said:

By 'overwrite editor modal', do you mean the one where you can overwrite a field's 'original' label, description, notes, etc for a specific template?

Yes.

11 minutes ago, kongondo said:

Are you able give me more details please?

I'd rather give you access to the site (as it is not yet live anyway) so that you can also use Tracy's file editor to poke around. What do you think?

BTW, I could not really uninstall the module, it was just FieldtypeRuntimeMarkup which seemingly went through the uninstall process, but PW – as expected – kept complaining about InputfieldRuntimeMarkup being used when I also clicked the uninstall button of that one. However, if I delete the RuntimeMarkup filed, I am back where I started.

Share this post


Link to post
Share on other sites
On 6/13/2019 at 1:36 PM, szabesz said:

I'd rather give you access to the site (as it is not yet live anyway) so that you can also use Tracy's file editor to poke around. What do you think?

OK, but before that, since another user has experienced some issues with the Utility Class, I think I'll just move the class to its own file and require it. We'll try that first to see if it solves your issue. Thanks.

  • Like 1

Share this post


Link to post
Share on other sites
On 6/21/2019 at 10:41 AM, kongondo said:

OK, but before that, since another user has experienced some issues with the Utility Class, I think I'll just move the class to its own file and require it. We'll try that first to see if it solves your issue.

Hello @kongondo

Any news on this issue? I also run into it when trying to export a textarea field via the standard field export feature of the admin. I don't really need Runtime Markup, maybe you can give me a quick guide on how to remove it manually (inluding how to clean up the db if needed?).

On 6/13/2019 at 2:17 PM, kongondo said:

Corrected in 007.

Has this version been version published yet?

Thanks in advance.

Share this post


Link to post
Share on other sites

Are there known limitations in the plugin?

For example i cannot resize an image.

Then I wanted to get the original image but I cannot get the url.
$image->url  gives me just the folder where the image is but not the file-name.
$image->basename gives me nothing.

Textfields are working as expected.

"PHP Runtime Code Mode" is set to "Paste PHP code".

Share this post


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

For example i cannot resize an image.

Then I wanted to get the original image but I cannot get the url.
$image->url  gives me just the folder where the image is but not the file-name.
$image->basename gives me nothing.

Hard to tell without seeing some code. Maybe you image field is set to contain multiple images. In that case $image->url may not work. Could we see some code please.

1 hour ago, 2hoch11 said:

"PHP Runtime Code Mode" is set to "Paste PHP code".

Please note that it is advisable to use the option Render PHP file(s) instead.

Share this post


Link to post
Share on other sites

@kongondo If you have some time, could you please look into the issue I have? Please see above. Thanks in advance!

 

Share this post


Link to post
Share on other sites

@kongondo

So in other words resizing images should work the same way like it works in the frontend…

However, now I have an external file (instead of pasting php in the backend) but there was no difference… then I added "first()" to the image and now it works as expected:

$imageResized = $image->first()->size(400,400);

This is pretty strange because I already have an output of this image field in the frontend and it works without "first()"…

Share this post


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

This is pretty strange because I already have an output of this image field in the frontend and it works without "first()"…

Aah. I see what is happening. It isn't strange, actually, but working as expected. When output formatting is off, the value of an image or file field is always a WireArray irrespective of the field's maximum files allowed or the setting in formatted value. There is a note on the field. Please see the screenshot on this post.

The reason you didn't need first() in the frontend is because output formatting is on there. In the backend, where your rtm external file is called, output formatting is off, hence the need for first(). You can test this by using TracyDebugger to dump the results of the image field in both your external rtm file and in the template file used in the frontend. You should see the backend dump returning Pageimages and the frontend one Pageimage as illustrated below.

bd(get_class($page->image));

Backend dump

single_image_of_off.png.a3609c441e27a2deece4ff05b7a70d39.png

Frontend dump

single_image_of_on.png.cfd1dd0022c15587455f5de9e5427fba.png

  • Thanks 1

Share this post


Link to post
Share on other sites
11 hours ago, szabesz said:

@kongondo If you have some time, could you please look into the issue I have? Please see above. Thanks in advance!

 

Oops, sorry, totally slipped my mind! I'll have a look 😄.

  • Thanks 1

Share this post


Link to post
Share on other sites

I have been using this module successfully for some time. Now I have a more complex use case. I want to update the page (in the admin) using ajax, rather than having to manually select "save". However, in this case, the data is submitted OK but the RuntimeMarkup script does not run and so the page is not properly updated. Any ideas?

Thanks.

Edit. I'm not entirely sure if the problem just lies with this module since, although the ajax is returning 'success' the normal fields don't appear to update either.

Share this post


Link to post
Share on other sites
13 hours ago, MarkE said:

Edit. I'm not entirely sure if the problem just lies with this module since, although the ajax is returning 'success' the normal fields don't appear to update either.

Solved now - the problem is in the jquery ajax call - using method: with version 1.8.3 - it should be type: prior to 1.9. See 

 

Share this post


Link to post
Share on other sites

@kongondo is there any update about how to properly uninstall this module ? i have same error message like @szabesz case.

Thanks

Share this post


Link to post
Share on other sites

Hmm... When I try to uninstall the module I get this error... ? 🤔

172829_Skrmbillede2020-03-21kl_18_50_35.thumb.png.f87e8f62bda52884ac39636b194a19b8.png

 

EDIT: //

Hmm... 

I don't know what changed but after having refreshed my modules the uninstaller worked

(Resolved)

 

All the best,

Jonatan

Share this post


Link to post
Share on other sites
On 3/10/2020 at 10:39 AM, pwfans said:

@kongondo is there any update about how to properly uninstall this module ? i have same error message like @szabesz case.

Thanks

Sorry all, I haven't yet found time to act on this. I need time to investigate it properly.

  • 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 MoritzLost
      Process Cache Control
      This module provides a simple solution to clearing all your cache layers at once, and an extensible interface to perform various cache-related actions.
      The simple motivation behind this module was that I was tired of manually clearing caches in several places after deploying a change on a live site. The basic purpose of this module is a simple Clear all caches link in the Setup menu which clears out all caches, no matter where they hide. You can customize what exactly the module does through it's configuration menu:
      Expire or delete all cache entries in the database, or selectively clear caches by namespace ($cache API) Clear the the template render cache. Clear out specific folders inside your site's cache directory (/site/assets/cache) Clear the ProCache page render cache (if your site is using ProCache) Refresh version strings for static assets to bust client-side browser caches (this requires some setup, see the full documentation for details). This is the basic function of the module. However, you can also add different cache management action through the API and execute them through the module's interface. For this advanced usage, the module provides:
      An interface to see all available cache actions and execute them. A system log and logging output on the module page to see verify what the module is doing. A CacheControlTools class with utility functions to clear out different caches. An API to add cache actions, execute them programmatically and even modify the default action. Permission management, allowing you granular control over which user roles can execute which actions. The complete documentation can be found in the module's README.
      Plans for improvements
      If there is some interest in this, I plan to expand this to a more general cache management solution. I particular, I would like to add additional cache actions. Some ideas that came to mind:
      Warming up the template render cache for publicly accessible pages. Removing all active user sessions. Let me know if you have more suggestions!
      Links
      https://github.com/MoritzLost/ProcessCacheControl ProcessCacheControl in the Module directory CHANGELOG in the repository Screenshots


    • By Macrura
      PrevNextTabs Module
      Github: https://github.com/outflux3/PrevNextTabs
      Processwire helper modules for adding page navigation within the editor.
      Overview
      This is a very simple module that adds Previous and Next links inline with the tabs on the page editor. Hovering over the tab shows the title of the previous or next page (using the admin's built in jqueryUI tooltips.)
      Usage
      This module is typically used during development where you or your editors need to traverse through pages for the purpose of proofing, flagging and/or commenting. Rather than returning to the page tree or lister, they can navigate with these links.
      Warnings
      If you are using PW version 2.6.1 or later, the system will prevent you from leaving the page if you have unsaved edits.
      For earlier versions, to avoid accidentally losing changes made to a page that might occur if a user accidentally clicks on one of these, make sure to have the Form Save Reminder module installed.
      http://modules.processwire.com/modules/prev-next-tabs/
    • By Gadgetto
      SnipWire - Snipcart integration for ProcessWire
      Snipcart is a powerful 3rd party, developer-first HTML/JavaScript shopping cart platform. SnipWire is the missing link between Snipcart and the content management framework ProcessWire.
      With SnipWire, you can quickly turn any ProcessWire site into a Snipcart online shop. The SnipWire plugin helps you to get your store up and running in no time. Detailed knowledge of the Snipcart system is not required.
      SnipWire is free and open source licensed under Mozilla Public License 2.0! A lot of work and effort has gone into development. It would be nice if you could donate an amount to support further development:

      Status update links (inside this thread) for SnipWire development
      2020-03-21 -- SnipWire 0.8.5 (beta) released! Improves SnipWires webhooks interface and provides some other fixes and additions 2020-03-03 -- SnipWire 0.8.4 (beta) released! Improves compatibility for Windows based Systems. 2020-03-01 -- SnipWire 0.8.3 (beta) released! The installation and uninstallation process has been heavily revised. 2020-02-08 -- SnipWire 0.8.2 (beta) released! Added a feature to change the cart and catalogue currency by GET, POST or SESSION param 2020-02-03 -- SnipWire 0.8.1 (beta) released! All custom classes moved into their own namespaces. 2020-02-01 -- SnipWire is now available via ProcessWire's module directory! 2020-01-30 -- SnipWire 0.8.0 (beta) first public release! (module just submitted to the PW modules directory) 2020-01-28 -- added Custom Order Fields feature (first SnipWire release version is near!) 2020-01-21 -- Snipcart v3 - when will the new cart system be implemented? 2020-01-19 -- integrated taxes provider finished (+ very flexible shipping taxes handling) 2020-01-14 -- new date range picker, discount editor, order notifiactions, order statuses, and more ... 2019-11-15 -- orders filter, order details, download + resend invoices, refunds 2019-10-18 -- list filters, REST API improvements, new docs platform, and more ... 2019-08-08 -- dashboard interface, currency selector, managing Orders, Customers and Products, Added a WireTabs, refinded caching behavior 2019-06-15 -- taxes provider, shop templates update, multiCURL implementation, and more ... 2019-06-02 -- FieldtypeSnipWireTaxSelector 2019-05-25 -- SnipWire will be free and open source Plugin Key Features
      Fast and simple store setup Full integration of the Snipcart dashboard into the ProcessWire backend (no need to leave the ProcessWire admin area) Browse and manage orders, customers, discounts, abandoned carts, and more Multi currency support Custom order and cart fields Process refunds and send customer notifications from within the ProcessWire backend Process Abandoned Carts + sending messages to customers from within the ProcessWire backend Complete Snipcart webhooks integration (all events are hookable via ProcessWire hooks) Integrated taxes provider (which is more flexible then Snipcart own provider) Useful Links
      SnipWire in PW modules directory SnipWire Docs (please note that the documentation is a work in progress) SnipWire @GitHub (feature requests and suggestions for improvement are welcome - I also accept pull requests) Snipcart Website  
      ---- INITIAL POST FROM 2019-05-25 ----
       
    • By horst
      Croppable Image 3
      for PW 3.0.20+
      Module Version 1.2.0
      Sponsored by http://dreikon.de/, many thanks Timo & Niko!
      You can get it in the modules directory!
      Please refer to the readme on github for instructions.
       
      - + - + - + - + - + - + - + - + - + - NEWS - 2020/03/19 - + - + - + - + - + - + - + - + - + - 
      There is a new Version in the pipe, that supports WebP too: 
       
      - + - + - + - + - + - + - + - + - + - NEWS - 2020/03/19 - + - + - + - + - + - + - + - + - + - 
       
       
      -------------------------------------------------------------------------
       
      Updating from prior versions:
       
      Updating from Croppable Image 3 with versions prior to 1.1.7, please do this as a one time step:
      In the PW Admin, go to side -> modules -> new, use "install via ClassName" and use CroppableImage3 for the Module Class Name. This will update your existing CroppableImage3 module sub directory, even if it is called a new install. After that, the module will be recogniced by the PW updater module, what makes it a lot easier on further updates.
      -------------------------------------------------------------------------
       
      For updating from the legacy Thumbnail / CropImage to CroppableImage3 read on here.
       
      -------------------------------------------------------------------------
       
×
×
  • Create New...