Jump to content
kongondo

Module: RuntimeMarkup Fieldtype & Inputfield

Recommended Posts

Hi @pwfans,

Welcome to the forums. I'm glad you are finding the module useful. 

On 7/13/2018 at 4:01 AM, pwfans said:

Button is actually <a href> to template which will open new page (yes very ugly behaviour, read below) contain custom php code , not inside <form> action because <form> not allowed inside textarea.

To prevent opening new page when click the button, make an <iframe> inside the template as a target button, that's it, beautifully execution like native form in admin page.

Could you please provide more information regarding this approach? I'm sure it would come handy to others using to look this module. For instance, what template are you referring to? A template file? Also, the bit about the <form> and the textarea is not clear.

Thanks!

Share this post


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

Hi @pwfans,

Welcome to the forums. I'm glad you are finding the module useful. 

Could you please provide more information regarding this approach? I'm sure it would come handy to others using to look this module. For instance, what template are you referring to? A template file? Also, the bit about the <form> and the textarea is not clear.

Thanks!

Sure, first pardon for my english 😞

1. Create  "wireRenderFile('name-of-file')" contain html code <a href='link to page x' target='iframe x'> link AND small size <iframe name="x"> depend on how much text result will be, give css class to a href so it is like any other in admin page button, iframe used here so when a href above clicked, the result will be displayed in iframe, not opening in new page.
DO NOT use <form><button></button></form> in this page, it can't be executed.

2. Create new 'page x'  and 'template x' file as a href link target in step 1 , processing code will be inside this template file, you can really flexible here by using get URL parameter in step 1, such ?id=something&status=something, example case is in invoice page, you can send different content email notification (unpaid vs paid) using one button.

Hope this can help somebody else trying to send mail in admin page edit.

  • Like 2

Share this post


Link to post
Share on other sites
33 minutes ago, pwfans said:

Hope this can help somebody else trying to send mail in admin page edit.

Thanks for the explanation! 🙂

  • Like 1

Share this post


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

Hope this can help somebody else trying to send mail in admin page edit.

Thank you for posting this. Sounds like an approach I could have taken. I chose to solve this a slightly different way though.

  • Like 1

Share this post


Link to post
Share on other sites

On the module FieldtypeRuntimeMarkup I have error according to roles. As superuser I don't have any error but as contributor I have
trying to Get property on non-object and the html code in the field is displayed as source.

The line pointed at is this one

 protected function renderMarkup(Page $page, Field $field) {

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

                //locally scope $pages to eval()
                $pages = $this->wire('pages');

    ------>    $str = eval($field->runtimeFields);

                //since we are dealing with custom PHP code but also want to make sure that only markup is returned
                //if eval() returns anything other than a string or an integer, we throw an error (e.g. if an object or array is returned)
                if (is_string($str) || is_int($str)) return $str;
                //we need to check if we are in admin. Otherwise with an error, in the frontend the name of the the Fieldtype is returned if we echo out the field
                elseif($this->wire('process')->className() == 'ProcessPageEdit') return $this->error($this->_('Only strings and integers should be returned by your custom code! $

        }

Thank you

Share this post


Link to post
Share on other sites

The error is caused by the code you entered in the field settings. The eval line above just executes the configured code. So if you show us that code, it might be possible to pinpoint the exact issue.

  • Like 2

Share this post


Link to post
Share on other sites

Hi BitPoet,

Here is my code
 

$texte="";
$leslangues=array(1=>"fr", 2=>"de",3=>"en",4=>"es",5=>"he",6=>"it",7=>"pt",8=>"ru");
foreach ($leslangues as $langue => $langue_str){
$element = $pages->find("template=clef, langue=$langue, limit=1, sort=-id")->first()->title;
$nombre=(int) filter_var($element, FILTER_SANITIZE_NUMBER_INT);
if (!$nombre){
$nombre=1;
}
$texte.="<b>$langue_str</b> : $nombre, ";
unset($nombre);
}
$texte=rtrim(rtrim($texte),",");
return $texte;

Thank you for your help.

Share this post


Link to post
Share on other sites

Since the only line with property access is

$element = $pages->find("template=clef, langue=$langue, limit=1, sort=-id")->first()->title;

it seems that your selector returns no results, so the call to first() returns null and accessing the title leads to the error. Your contributor account may not have permissions on the template or the pages in question may be hidden or unpublished. Depending on the exact scenario, an additional selector is probably necessary (see the link for details).

  • Like 1

Share this post


Link to post
Share on other sites

What I don't understand is that the field is displayed anyway with the right data (each language has a number) but displaying the b tag.

Share this post


Link to post
Share on other sites

Thank you very Much BitPoet for your help, I was able to solve adding check_access=0 in my selector.

Great!

Share this post


Link to post
Share on other sites

Looking for help on this one. I have a RuntimeMarkup field in a template.

When I only return a string with no HTML markup, all is well. See image 1 where the RTM field is "Skills" and it's returning the title of an auto-generated FormBuilder entry with no HTML.

642448032_Screenshot2019-01-1618_09_33.thumb.png.2c41d0e50e8408dd4e92a2492fbb52d5.png

When I try to output more info from the FormBuilder entry & format it, the page CSS loses the plot. Not only are the UiKit3 styles ignored, much of the page CSS is broken too - note the Save Edit button and the stacked-rather-than-styled fields above it.

1230224745_Screenshot2019-01-1618_11_11.thumb.png.49a18a5986e9b397eb8c95169684841c.png

RTM CSS file is as default and all that's returned to the field is a valid string. I've even tried returning a valid HTML string with heading & paragraph tags to take FormBuilder out of the equation.

The output string is:

    <div>
      <h3 class="uk-h3">Skills</h3>
      <div class="uk-width-3-4">some other skill</div>
      <div class="uk-width-1-4">65%</div>
      <div class="uk-width-3-4">talking under water</div>
      <div class="uk-width-1-4">80%</div>
      <div class="uk-width-3-4">Yawning</div>
      <div class="uk-width-1-4">100%</div>
      <div class="uk-width-3-4">Balloon animals</div><div class="uk-width-1-4">80%</div>
</div>

Actually doesn't seem to matter what HTML tags or classes I enter, as soon as I do, the page CSS breaks. Believe me, I tried lots!

RuntimeMarkup is a @kongondo module

Any suggestions on where and how to fix?

PS: Text in the summary field comes from https://baconipsum.com/ - I like it spicy!

Share this post


Link to post
Share on other sites

@Chris Bennett ummn, not sure... went to PW Modules to get it - version 0.0.2

According to the Modules site & @kongondo's github site, I am.

There are a couple of modules that do similar. Please give me the URL to the one you used 😊

It's important to this site that I can "do stuff" in PHP/PW before outputting the string

Thanks

Share this post


Link to post
Share on other sites
1 minute ago, psy said:

@Chris Bennett ummn, not sure... went to PW Modules to get it - version 0.0.2

According to the Modules site & @kongondo's github site, I am.

There are a couple of modules that do similar. Please give me the URL to the one you used 😊

It's important to this site that I can "do stuff" in PHP/PW before outputting the string

Thanks

No worries Psy, give me a minute to look-see what I have and try to track down where I got it 

Share this post


Link to post
Share on other sites

@Chris Bennett thanks, a step in the right direction. Now can output direct HTML and it works fine but still problems when I try to construct the string from my function

Share this post


Link to post
Share on other sites

@psy,

I have moved your topic here since this is the support forum of the module 🙂

Apologies, I have not had the time to finish up on some new features and merger the dev version into master. 

11 minutes ago, psy said:

still problems when I try to construct the string from my function

I don't understand this. Please clarify:

  1. What function is this? Can we see the code please
  2. Where are you calling the function? Directly in RuntimeMarkup field settings or it is in a file and you are calling it using wireRenderFile() or $files?
  3. Errors in dev console?
  4. Can we see the output from the FormBuilder entry

Share this post


Link to post
Share on other sites

@kongondo thanks for chipping in 🙂 

My function is in a custom module and the code in the RTM field is:

$custom = $this->wire('modules')->get('CustomFunctionsTBR');
return $custom->getJobSeekerData ($page);

The function in CustomFunctionsTBR is:

    function getJobSeekerData ($page) {

        $skills = $this->formMultiple('jobseeker_skills', $page->user_id);
        $out = "";
        $out .= "<h3 class='uk-h3'>Skills</h3>";
        foreach ($skills['entries'] as $entry){
            $out .= "<div class='uk-width-3-4'>" . $entry['skill_name'] . "</div><div class='uk-width-1-4'>" . $entry['skill_level']. "%</div>";
        }
        return $out;
    }

Where $this->formMultiple function queries the FormBuilder entries for records based on a user id saved (but not displayed) on the page.

There are no errors in the dev console.

Output from var_dump just prior to returning $out in the CustomFunctionsTBR FormBuilder entry:

string(355) "<h3 class='uk-h3'>Skills</h3><div class='uk-width-3-4'>some other skill</div><div class='uk-width-1-4'>65%</div><div class='uk-width-3-4'>talking under water</div><div class='uk-width-1-4'>80%</div><div class='uk-width-3-4'>Yawning</div><div class='uk-width-1-4'>100%</div><div class='uk-width-3-4'>Balloon animals</div><div class='uk-width-1-4'>80%</div>"
string(355) "<h3 class='uk-h3'>Skills</h3><div class='uk-width-3-4'>some other skill</div><div class='uk-width-1-4'>65%</div><div class='uk-width-3-4'>talking under water</div><div class='uk-width-1-4'>80%</div><div class='uk-width-3-4'>Yawning</div><div class='uk-width-1-4'>100%</div><div class='uk-width-3-4'>Balloon animals</div><div class='uk-width-1-4'>80%</div>"

Seems to be rendering the output twice - have heard of this anomaly happening before, eg in certain repeater matrix situations...???

Or maybe it's late and I'm tired.

Any/all suggestions to fix are welcome.

Share this post


Link to post
Share on other sites

@psy,

Thanks for the info.

I have not been able to replicate this. I've used your example HTML strings and it works just fine. Page Edit renders fine. I even tried with invalid/broken HTML and nothing breaks; it works OK. 

3 hours ago, psy said:

When I try to output more info from the FormBuilder entry & format it,

I missed this earlier. What do you mean 'format it'?

I'm wondering if your string is maybe returning invalid HTML that somewhere trips the browser? Just guessing. Other than that, RuntimeMarkup's CSS and JS files are blank; they never return anything. I need to remove them actually as they don't do anything.

If all else fails, I'm happy to have a look around your install if that's possible.

  • Like 2

Share this post


Link to post
Share on other sites

@kongondo, thank you!

New day here and taking another look. I noticed in the code that even though I'm only calling FormBuilder to get the entries, all the FB scripts & css are loading into the <head>. Digging deeper to see if this is causing a conflict. Grateful for your offer to look around the code if I can't resolve it. Will keep you posted.

 

More: Yep, FormBuilder files seem to be the problem. Now to figure out how to use FB in admin area to get the entries without the scripts loading.

 

SOLVED: One of the things my custom function 'formsMultiple' did was render the form and add the output to the final returned array. Works great on the front end but not needed here. Made the form rendering optional in the 'formsMultiple' function and in the RTM code, said don't do it. End result is RTM field and rest of the admin page display as expected. Thanks for the help & pointing me in the right direction.

Edited by psy
Solved problem
  • Like 1

Share this post


Link to post
Share on other sites

I just had a very weird issue today... I'll try and describe it as best as I can:

I have a frontend search form (text search and filters), which used to work fine before I have installed and used the RTMU module. Today the following fatal error appeared:

Spoiler

Exception: Field 'offer_reference_chooser' is runtime and not queryable (in /home/sitecom/www/dev.webapp/site/assets/cache/FileCompiler/site/modules/FieldtypeRuntimeMarkup/FieldtypeRuntimeMarkup.module line 181)

#0 /home/sitecom/www/dev.webapp/wire/core/PageFinder.php(1268): FieldtypeRuntimeMarkup->getMatchQuery(Object(ProcessWire\DatabaseQuerySelect), 'field_offer_ref...', 'data', '%=', '')
#1 /home/sitecom/www/dev.webapp/wire/core/Wire.php(386): ProcessWire\PageFinder->___getQuery(Object(ProcessWire\Selectors), Array)
#2 /home/sitecom/www/dev.webapp/wire/core/WireHooks.php(723): ProcessWire\Wire->_callMethod('___getQuery', Array)

PW basically tripped over these lines:

public function getMatchQuery($query, $table, $subfield, $operator, $value) {
	// we don't allow this field to be queried
	throw new WireException("Field '{$query->field->name}' is runtime and not queryable");
}

Now, the strange thing is: I am carefully constructing my selector (only pages within parent 1041, with template 'project' etc.etc.). The only template that used the RTMU inputfield was NOT the template I was querying. I have used it in another template, along with a page-reference field. Now this page-reference field was configured to show template 'project' pages, and children of page 1041.

Now that I have deleted the inpufields / removed them from my other template, everything works fine again.

How can it happen that this inputfield is somehow interferring a PW selector / search?

For a second, I thought I could also just comment this line:

// throw new WireException("Field '{$query->field->name}' is runtime and not queryable");

but then again, I don't know what else I could possibly break somewhere else by accident.

@kongondo Do you have any idea? Did you ever run into similar issues?

SERVER DETAILS
ProcessWire: 3.0.124
PHP: 7.2.14
Webserver: Apache/2.4
MySQL: 10.1.35-MariaDB

InputfieldRuntimeMarkup: 0.0.2
TracyDebugger: 4.15.8
 

PS

The module worked fine for me otherwise! I have used it to add a link which opens a frontend-page in a modal:

return '<a class="pw-panel pw-panel-reload ui-corner-all ui-button ui-widget ui-corner-all ui-state-default" href="https://dev.webapp.mysite.com/somepage/" data-tab-text="Choose x y z" data-tab-icon="eye" id="proj_chooser" role="menuitem"><i class="fa fa-fw fa-search"></i> search / choose</a>';

 

Edited by dragan
added PS

Share this post


Link to post
Share on other sites
8 hours ago, dragan said:

Do you have any idea? Did you ever run into similar issues?

That's strange. I've never seen this.

I could do some testing but I'm finding it a bit hard to follow your setup (the project template, 1041, etc). If I could see an illustration of how everything connects plus your selector string as well as any code or setup you use for the page-reference field, that would help. Seeing what Tracy returns as a final selector would also be helpful.

Share this post


Link to post
Share on other sites

How do I get a reference to the repeater page, instead of the page the repeater is on?
$page->id returns the parent or containing page, rather than the repeater id.

[SOLVED]

$value = $this->hasPage->data['some_field'];

 

Share this post


Link to post
Share on other sites

Hey @kongondo - I am back working on that project that makes heavy use of this field and I just replaced the:

return $this->renderMarkup($page, $field);

with:

return true;

for the sleep, wakeup, and loadPageField methods and it is bringing calls to the render method back to just one, which is really important because it contains some heavy querying.

I am fine with this mod for my needs, but I wonder if you'd consider these as an option for when the module is only used in the admin. The render() method in the InputRuntimeMarkup file takes care of the actual rendering without all these duplicate calls to renderMarkup().

What do you think?

  • Like 3

Share this post


Link to post
Share on other sites
5 hours ago, adrian said:

I am fine with this mod for my needs, but I wonder if you'd consider these as an option for when the module is only used in the admin. The render() method in the InputRuntimeMarkup file takes care of the actual rendering without all these duplicate calls to renderMarkup().

What do you think?

Thanks for resolving the issue! I don't get the bit about only used in admin; do you mean use a condition to check whether in admin? If you tested and it works find in the frontend as well with your mod, that's great! If the mod affects the frontend, then we can do the condition check for admin. It's been a while since I looked at the module and the master branch is beginning to really lag behind the dev branch. If you can write some code for me here rather than a PR, I'll appreciate it, 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 MoritzLost
      TrelloWire
      This is a module that allows you to automatically create Trello cards for ProcessWire pages and update them when the pages are updated. This allows you to setup connected workflows. Card properties and change handling behaviour can be customized through the extensive module configuration. Every action the module performs is hookable, so you can modify when and how cards are created as much as you need to. The module also contains an API-component that makes it easy to make requests to the Trello API and build your own connected ProcessWire-Trello workflows.
      Features
      All the things the module can do for you without any custom code: Create a new card on Trello whenever a page is added or published (you can select applicable templates). Configure the target board, target list, name and description for new cards. Add default labels and checklists to the card. Update the card whenever the page is updated (optional). When the status of the card changes (published / unpublished, hidden / unhidden, trashed / restored or deleted), move the card to a different list or archive or delete it (configurable). You can extend this through hooks in many ways: Modifiy when and how cards are created. Modify the card properties (Target board & list, title, description, et c.) before they are sent to Trello. Create your own workflows by utilizing an API helper class with many convenient utility methods to access the Trello API directly. Feedback & Future Plans
      Let me know what you think! In particular:
      If you find any bugs report them here or on Github, I'll try to fix them. This module was born out of a use-case for a client project where we manage new form submissions through Trello. I'm not sure how many use-cases there are for this module. If you do use it, tell me about it! The Trello API is pretty extensive, I'll try to add some more helper methods to the TrelloWireApi class (let me know if you need anything in particular). I'll think about how the module can support different workflows that include Twig – talk to me if you have a use-case! Next steps could be a dashboard to manage pages that are connected to a Trello card, or a new section in the settings tab to manage the Trello connection. But it depends on whether there is any interest in this 🙂 Links
      Repository on Github Complete module documentation (getting started, configuration & API documentation) TrelloWire in the modules directory Module configuration

    • 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-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 bernhard
      #######################
      Please use the new RockFinder2
      #######################
      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://github.com/BernhardBaumrock/RockFinder
       
      Changelog
      180817, v1.0.6, support for joining multiple finders 180810, v1.0.5, basic support for options fields 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/
    • 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/
×
×
  • Create New...