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
On 3/27/2020 at 2:42 AM, kongondo said:

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

Encountered this issue too. The following change to InputfieldRuntimeMarkup appears to have fixed the missing utilities class:

<?php

	public function init() {
		// parent::init();
		// get the helper class (included in FieldtypeRuntimeMarkup.module file)
        $this->classLoader->loadClass('FieldtypeRuntimeMarkup'); // add this line to ensure the RuntimeMarkupUtilities class is available
		$this->rtmUtilities = new RuntimeMarkupUtilities();
	}

Can now install, uninstall, create & delete fields, etc without problems.

I needed this module for a FormBuilder form but sadly the module's configurable fields aren't available in FormBuilder 😢

  • 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 d'Hinnisdaël
      Happy new year, everybody 🥬
      I've been sitting on this Dashboard module I made for a client and finally came around to cleaning it up and releasing it to the wider public. This is how it looks.
      ProcessWire Dashboard

      If anyone is interested in trying this out, please go ahead! I'd love to get some feedback on it. If this proves useful and survives some real-world testing, I'll add this to the module directory.
      Download
      You can find the latest release on Github.
      Documentation
      Check out the documentation to get started. This is where you'll find information about included panel types and configuration options.
      Custom Panels
      My goal was to make it really simple to create custom panels. The easiest way to do that is to use the panel type template and have it render a file in your templates folder. This might be enough for 80% of all use cases. For anything more complex (FormBuilder submissions? Comments? Live chat?), you can add new panel types by creating modules that extend the DashboardPanel base class. Check out the documentation on custom panels or take a look at the HelloWorld panel to get started. I'm happy to merge any user-created modules into the main repo if they might be useful to more than a few people.
       Disclaimer
      This is a pre-release version. Please treat it as such — don't install it on production sites. Just making sure 🍇
      Roadmap
      These are the things I'm looking to implement myself at some point. The wishlist is a lot longer, but those are the 80/20 items that I probably won't regret spending time on.
      Improve documentation & add examples ⚙️ Panel types Google Analytics ⚙️ Add new page  🔥 Drafts 🔥 At a glance / Page counter 404s  Layout options Render multiple tabs per panel panel groups with heading and spacing between ✅ panel wrappers as grid item (e.g. stacked notices) ✅ Admin themes support AdminThemeReno and AdminThemeDefault ✅ Shortcuts panel add a table layout with icon, title & summary ✅ Chart panel add default styles for common chart types ✅ load chart data from JS file (currently passed as PHP array) Collection panel support image columns ✅ add buttons: view all & add new ✅
    • By Pip
      Hi everyone!
      I'm trying out the Login/Register module for my site. Noted that the module assigns the newly registered user to login-register role. 
      Once you modify the login-register role's permissions, particularly adding page-edit, the new member role will be set to guest. 
      Thing is I'd like to grant my new users the power to create their own pages. Any advice? 
      Thanks. 
    • 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-07-03 -- SnipWire 0.8.7 (beta) released! Fixes some small bugs and adds an indicator for TEST mode 2020-04-06 -- SnipWire 0.8.6 (beta) released! Adds support for Snipcart subscriptions and also fixes some problems 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 Sten
      Hello
      Till now I hacked something with the twig template but it works no more with new PW versions so I look forward to create a module. I am working on a site in multiple languages : French, English, Italian, German, Spanish, Portuguese, Hebrew, Russian. The new posts are entered in any language with a field for language. Till now, I got twig files to get the translations with constants defined for each part of the pages.
      So I'd like to create a module to include theses files added according to the url /fr/en/...
      Have you some observations to do before I begin about the direction to take ?
      Thank you
    • By ukyo
      Mystique Module for ProcessWire CMS/CMF
      Github repo : https://github.com/trk/Mystique
      Mystique module allow you to create dynamic fields and store dynamic fields data on database by using a config file.
      Requirements
      ProcessWire 3.0 or newer PHP 7.0 or newer FieldtypeMystique InputfieldMystique Installation
      Install the module from the modules directory:
      Via Composer:
      composer require trk/mystique Via git clone:
      cd your-processwire-project-folder/ cd site/modules/ git clone https://github.com/trk/Mystique.git Module in live reaction with your Mystique config file
      This mean if you remove a field from your config file, field will be removed from edit screen. As you see on youtube video.
      Using Mystique with your module or use different configs path, autoload need to be true for modules
      Default configs path is site/templates/configs/, and your config file name need to start with Mystique. and need to end with .php extension.
      Adding custom path not supporting anymore !
      // Add your custom path inside your module class`init` function, didn't tested outside public function init() { $path = __DIR__ . DIRECTORY_SEPARATOR . 'configs' . DIRECTORY_SEPARATOR; Mystique::add($path); } Mystique module will search site/modules/**/configs/Mystique.*.php and site/templates/Mystique.*.php paths for Mystique config files.
      All config files need to return a PHP ARRAY like examples.
      Usage almost same with ProcessWire Inputfield Api, only difference is set and showIf usage like on example.
      <?php namespace ProcessWire; /** * Resource : testing-mystique */ return [ 'title' => __('Testing Mystique'), 'fields' => [ 'text_field' => [ 'label' => __('You can use short named types'), 'description' => __('In file showIf working like example'), 'notes' => __('Also you can use $input->set() method'), 'type' => 'text', 'showIf' => [ 'another_text' => "=''" ], 'set' => [ 'showCount' => InputfieldText::showCountChars, 'maxlength' => 255 ], 'attr' => [ 'attr-foo' => 'bar', 'attr-bar' => 'foo' ] ], 'another_text' => [ 'label' => __('Another text field (default type is text)') ] ] ]; Example:
      site/templates/configs/Mystique.seo-fields.php <?php namespace ProcessWire; /** * Resource : seo-fields */ return [ 'title' => __('Seo fields'), 'fields' => [ 'window_title' => [ 'label' => __('Window title'), 'type' => Mystique::TEXT, // or InputfieldText 'useLanguages' => true, 'attr' => [ 'placeholder' => __('Enter a window title') ] ], 'navigation_title' => [ 'label' => __('Navigation title'), 'type' => Mystique::TEXT, // or InputfieldText 'useLanguages' => true, 'showIf' => [ 'window_title' => "!=''" ], 'attr' => [ 'placeholder' => __('Enter a navigation title') ] ], 'description' => [ 'label' => __('Description for search engines'), 'type' => Mystique::TEXTAREA, 'useLanguages' => true ], 'page_tpye' => [ 'label' => __('Type'), 'type' => Mystique::SELECT, 'options' => [ 'basic' => __('Basic page'), 'gallery' => __('Gallery'), 'blog' => __('Blog') ] ], 'show_on_nav' => [ 'label' => __('Display this page on navigation'), 'type' => Mystique::CHECKBOX ] ] ]; Searching data on Mystique field is limited. Because, Mystique saving data to database in json format. When you make search for Mystique field, operator not important. Operator will be changed with %= operator.
      Search example
      $navigationPages = pages()->find('my_mystique_field.show_on_nav=1'); $navigationPages = pages()->find('my_mystique_field.page_tpye=gallery');
×
×
  • Create New...