kongondo

Module: RuntimeMarkup Fieldtype & Inputfield

Recommended Posts

@berhard - In the module when a RuntimeMarkupField runs inside a repeater, $page references the page that the repeater is on, not the repeater iteration instance.

Share this post


Link to post
Share on other sites

@Gazley, we can probably get around that. The main issue for me is how to reference the current repeater matrix item, basically the 'neighbouring' page field. In normal repeaters, fields are grouped (using their modified field-names) like so in one repeater item:

email_repeater3157            page_field_name_repeater3157             runtime_markup_field_name3157         eq(0)

email_repeater3179            page_field_name_repeater3179             runtime_markup_field_name3179         eq(1)

What is needed is a way to get the eq(n) of the repeater or the 3157 (the ID of the page where the fields actually live - hidden repeater page in admin)

Btw, $page->getForPage() won't cut it because this is the current page that has all those repeater items, in other words the $page in your RuntimeMarkup field. It seems the $page variable will do it? I don't even have a PW 3.x install ( :-X ) which RepeaterMatrix requires to test this. Time, oh time...

Edited by kongondo

Share this post


Link to post
Share on other sites

I added this small tweak to the FieldType, which allows me to use the Ace extended for my code editing..

if(wire('modules')->get('InputfieldAceExtended')) {
	$f = $this->modules->get('InputfieldAceExtended');
	$f->mode = "php";
	$f->theme = "monokai";
} else {
	$f = $this->modules->get('InputfieldTextarea'); 
}
  • Like 4

Share this post


Link to post
Share on other sites

Thanks Macrura...had let this slip under the radar. I'll add it as an option so users get to choose (and why wouldn't they?) if they want the textarea formatted with ace or not...

  • Like 3

Share this post


Link to post
Share on other sites

cool - yeah the only slight snafu is that if you want syntax highlighting, you have to add an opening php tag, so if i'm editing, i add that and then i delete it before saving; not sure though if there is any way around that, but haven't looked into it yet...

Share this post


Link to post
Share on other sites
Error: Call to undefined function wireRenderFile() (line 1 of .../FieldtypeRuntimeMarkup.module(98) : eval()'d code) 
This error message was shown because: you are logged in as a Superuser. Error has been logged.

hi @kongondo

i get this error after updating from pw 2.7.3 to pw 3.0.28

i have this in my custom php field:

return wireRenderFile('_pageactions');

changing it to this:

namespace Processwire;
return wireRenderFile('_pageactions');

solves the problem. don't know how bullet-proof this is? maybe you could add this automatically when using namespaces?

Share this post


Link to post
Share on other sites

thanks again for this awesome field! if anybody needs excel-like tables this is easily possible like this (startingpoint):

  • create a folder like /site/modules/HandsonTable
  • copy https://github.com/handsontable/handsontable to this folder
  • create a runtime field with this content: return wireRenderFile('../modules/HandsonTable/HandsonTable.php');
  • create your php-file /site/modules/HandsonTable/HandsonTable.php
<?php
$config->scripts->append($config->urls->siteModules . "HandsonTable/handsontable/dist/handsontable.full.js");
$config->scripts->append($config->urls->siteModules . "HandsonTable/handsontable/dist/moment/moment.js");
$config->scripts->append($config->urls->siteModules . "HandsonTable/handsontable/dist/pikaday/pikaday.js");
$config->styles->append($config->urls->siteModules . "HandsonTable/handsontable/dist/handsontable.full.css");
$config->styles->append($config->urls->siteModules . "HandsonTable/handsontable/dist/pikaday/pikaday.css");
?>

<div id="example"></div>
<script>
var data = [
  ["", "Ford", "Volvo", "Toyota", "Honda"],
  ["2016", 10, 11, 12, 13],
  ["2017", 20, 11, 14, 13],
  ["2018", 30, 15, 12, 13]
];

var container = document.getElementById('example');
var hot = new Handsontable(container, {
  data: data,
  rowHeaders: true,
  colHeaders: true
});
</script>

moment and pickaday are not needed in this example and just as a showcase and reminder...

2016-09-16 15_46_57-Edit Page_ Impulstag für Motivation und Erfolg - Graz (Listenexport) • mentalest.png

It get's a little more complicated if you need storing/editing features but i need it only to show some data and my client can copy/paste data to excel/google drive sheets.

  • Like 7

Share this post


Link to post
Share on other sites
On 02/08/2016 at 11:31 AM, bernhard said:

Error: Call to undefined function wireRenderFile() (line 1 of .../FieldtypeRuntimeMarkup.module(98) : eval()'d code) 
This error message was shown because: you are logged in as a Superuser. Error has been logged.

hi @kongondo

i get this error after updating from pw 2.7.3 to pw 3.0.28

i have this in my custom php field:


return wireRenderFile('_pageactions');

changing it to this:


namespace Processwire;
return wireRenderFile('_pageactions');

solves the problem. don't know how bullet-proof this is? maybe you could add this automatically when using namespaces?

I think it's easier if the dev themselves added the namespace. Even this one-liner would have worked for you...

return ProcessWire\wireRenderFile('_pageactions');

 

Share this post


Link to post
Share on other sites

Announcing that I've tested and can confirm that RuntimeMarkup is compatible with ProcessWire 2.8.x and ProcessWire 3.x

  • Like 6

Share this post


Link to post
Share on other sites

Hi Kongondo

I have tried your master and dev versions with PW 3.0.36 and only get errors.

Using your example code or something simple like 'return $page->parent->title;'  gets the resulting error:

Only strings and integers should be returned by your custom code! Check if your code is valid.

'return "hello";' works - but thats not so useful.

I am running php 5.4.4  -  might that be the issue?

 

Kind regards

Nik

 

Share this post


Link to post
Share on other sites

@NikNak. Works fine for me on PW 3.0.42 and PHP 5.4.22 .  You need to ensure that your code returns a value. For wireRenderFile you will need to namespace the function in PW 3.

 

Share this post


Link to post
Share on other sites

Thanks.

I tried the simplest of things, and namespaced it too, but couldnt get any output other than an error.

Not to worry - I'll do more testing.

Many thanks

Nik

Share this post


Link to post
Share on other sites

Any chance $page->parent->title; is returning an object due to multi-language?

Share this post


Link to post
Share on other sites

I've done some more testing. The module is working on normal pages whereas I was initially trying it out on $user pages, where it failed.  

Kind regards

Nik

Share this post


Link to post
Share on other sites
return wire('users')->get(40)->name;

@NikNak

That will return guest. Only $page and $pages are locally scoped, as per the description right above the input for code;). I guess that and the docs should perhaps be clearer.

Share this post


Link to post
Share on other sites

Thanks Kongondo - it's just me being thicker than usual - no problem with the description ;-)

 

I assume this means that you cannot self reference fields on a $user page being edited.

EDIT: The below solves what I was trying to do - thanks Kongondo

$process = wire('process'); 
$u = $process->getPage();
$id = $u->id;
return $id;// will return 40 for guest, 41 for superuser, etc...
//return $process->className();// would return ProcessUser. Useful to know if you are using the field elsewhere and want to do different things based on context
// return $u->email;// etc...

 

Kind regards

Nik

Edited by NikNak

Share this post


Link to post
Share on other sites

Just came here to say that this module works brilliantly!

I have made an "email sender field" that uses the page's data to manage surveys for a certain product and right now I'm doing a "defaults selection for repeater field" for a repeatear field with page fields in it that will describe features of a product. It's really nice to just hack your way so fast with this!

I use it with wireRenderFile() which rules because it lets me handle the markup nicely in a separate file in my preferred text editor.

EDIT: Added "mail settings" screenshot. Jus realized my description text is all messed up engrish

Screen Shot 2017-01-11 at 8.11.32 AM.png

  • Like 4

Share this post


Link to post
Share on other sites

I tried this module today to output a video preview from a multilanguage field. Worked like a charm. :) See the screenshot.

I created two fields, one for the default language (English) and one for Portuguese. 

Here's the code for both, if someone's interested:

English field:

return '<iframe src="https://www.youtube.com/embed/'.$page->youtube_id.'/?showinfo=0&amp;iv_load_policy=3&amp;controls=1" frameborder="0" allowfullscreen width="100%"></iframe>';

Portuguese field:

//1021 is the 'portuguese' language page id
$youtube_id = $page->youtube_id->getLanguageValue(1021);

return '<iframe src="https://www.youtube.com/embed/'.$youtube_id.'/?showinfo=0&amp;iv_load_policy=3&amp;controls=1" frameborder="0" allowfullscreen width="100%"></iframe>';

Thanks @kongondo for this great module!

video_preview.png

  • Like 8

Share this post


Link to post
Share on other sites

Hi there,

I use this field type with translateable strings and it works. My problem is I cannot find where I could translate it in the backend.

Example:

Fieldname: calendarbox

PHP code inside this field:

Screenshot_4.jpg

The output in the backend works. Maybe I have to create the translateable file manually.

Can anyone help me out?

Best regards

Share this post


Link to post
Share on other sites

i guess you could use wireRenderFile, then it should show up in the backend.

  • Like 2

Share this post


Link to post
Share on other sites

Just a quick by the way, I recently updated the first post in this thread to state that the wireRenderFile() approach is the recommended way to use this module. I'll update the README too when I get the time.

  • Like 4

Share this post


Link to post
Share on other sites

you could also put everything in one file to have all translations aggregated in one page in the admin

custom code:

return wireRenderFile('fieldmarkup', array('field' => 'calendarbox'));

fieldmarkup.php

<?php
switch ($field) {
    case 'calendarbox':
        $out = '<div>...</div>';
        $out .= '<p>...</p>';
        echo $out;
        break;
}

i guess for easy fields that would be better than having a file for each field...

  • Like 4

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 kixe
      Email Verification
      This module provides functions to validate email adresses and hosts. The module generates a textfile for blacklisted mailhosts (trashmail), which will be always up to date.
      Download
      https://modules.processwire.com/modules/email-verification/
      API
      // get module $mailcheck = $modules->get('EmailVerification'); // return bool/ string - automatted update of blacklist file $mailcheck->blacklisted(email|domain) // return bool - validate a top level domain, checks against IANA list $mailcheck->validTLD(tld) // return array of punycoded TLDs - cyclic updated, data pulled from IANA $mailcheck->getTLDs(cycle=2592000) // return bool - checks syntax converts to punycode $mailcheck->validDomainName(domain); // return bool - checks punycode encoded syntax $mailcheck->validHostName(host); // return bool - checks syntax and accessibility $mailcheck->validHost(email|domain) // add a single value to blacklist $mailcheck->addToBlacklist(email|domain) USAGE
      $mailcheck = $modules->get('EmailCheck'); $email = 'susi@trashmail.com'; if($mailcheck->blacklisted($email)) echo 'Email Provider not allowed'; if(!$mailcheck->validHost($email)) echo 'Mailhost not available'; Example blacklist file:  blacklist.txt
       
    • By teppo
      Code Blocks Textformatter is a tiny Textformatter module I cooked up to add support for code blocks to text/textarea/RTE fields on some of the sites I work with. Unlike a full-blown Markdown Textformatter – which is something that we already have in the core – this module simply adds support for fenced and inline code blocks.
      The syntax is based on the GitHub code block documentation, so please refer to that for additional instructions. The README at GitHub also includes some basic examples. As with any Textformatter, in order to enable this one, install it and enable it via field settings. Note that there's no syntax highlighting built in (at least for the time being), so use a tool of your choice for that – personally I prefer Prism.js.
      Since this module doesn't use a Markdown tool behind the scenes, but rather some home baked regular expressions, there's always the possibility that I've missed something – but please let me know if you use this module and run into any issues. On the other hand this module should be relatively fast and unobtrusive, as there are no unnecessary bits of code to run 
      GitHub repository: https://github.com/teppokoivula/TextformatterCodeBlocks Modules directory: http://modules.processwire.com/modules/textformatter-code-blocks/
    • By theo
      Here is my first processwire module (beta).
      https://github.com/theo222/ImagePickerField
      A lot of "first times". First time Github, Markdown and of course PW Modules.
      So be gentle please.
      I hope it works.

    • By horst
      Image Animated GIF  v 2.0.2
       
      Module for PW 2.5 stable or newer, but is obsolete for PW Versions greater then 3.0.89 (... read more ...)
       
      This module helps with resizing and cropping of animated GIFs when using the GD-Library.
      The GD-Library does not support this.


      This module is completely based upon the fantastic work of

         László Zsidi (http://www.gifs.hu/, builts the initial classes)
         xurei (https://github.com/xurei/GIFDecoder_optimized, enhanced the classes)


      I have ported it to a PW module and it works with core imagefields, together with Pia and with CropImagefields that uses the new naming scheme since PW 2.5.
       
      ------------------------------------------------------------------------------------------------------------------------------------------
      read more in this post about the rewrite from version 1.0.0 to version 2.0.0
      ------------------------------------------------------------------------------------------------------------------------------------------
      You can find it in the modules directory: https://modules.processwire.com/modules/image-animated-gif/
      and on Github: https://github.com/horst-n/ImageAnimatedGif
      ------
      A preview can be found here