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 6

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

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

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

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 netcarver
      Part 1 of a 2 part Module & Service Reveal.
      I'm currently working on a new module: ModuleReleaseNotes that was inspired by the work I originally did on making Ryan's ProcessWireUpgrades module "release" aware. In the end, I decided to ditch the approach I was originally taking and instead work on a module that hooked in to the UpgradeConfirmation dialog and the module edit page.
      Aims
      My aims for this module are as follows...
      Make discovery of a module's changes prior to an upgrade a trivial task. Make breaking changes very obvious. Make reading of a module's support documentation post-install a trivial task. Make module authors start to think about how they can improve the change discovery process for their modules. Make sure the display of information from the module support files/commit messages doesn't introduce a vulnerability. Looking at these in turn...
      Making discovery of a module's changes prior to upgrade a trivial task.
      This is done by adding a "What's changed section" to the upgrade confirmation dialog.  This section takes a best-effort approach to showing what's changed between the installed version and the updated version that's available via the module repository.
      At present, it is only able to talk to github-hosted repositories in order to ask them for the release notes, the changelog file (if present) and a list of commits between the git tag that matches the installed version and the tag matching the latest version.
      It will display the Release Notes (if the author is using the feature), else it will display the commits between the tags (if tagging is used by the module author) else it will show the changelog file (if present) else it will show the latest N commits on the master branch (N, of course, being configurable to your liking.)
      An example of the Github Release Notes pulled in for you, taken from Mike Rockett's TextformatterTypographer Module...

      An example of a tag-to-tag commit list from the same module...

      An example of a changelog - formatted to show just the changes (formatting styles will change)...

      Finally, an example of a fallback list of commits - sorry Adrian ...

       
      Making breaking changes obvious.
      This is currently done by searching for a set of configurable search strings. Later versions may be able to support breaking change detection via use of Semantic Versioning - but this may require some way of signalling the use of this versioning standard on a module-by-module basis.
      For now, then, you can customise the default set of change markers. Here I have added my own alias to the list of breaking change markers and the changes section of the changelog is styled accordingly (these will be improved)...

       
      Make reading of a module's support documentation, post-install, a trivial task.
      This is done by making some of the support files (like the README, CHANGELOG and LICENSE files) readable from the module's information/settings screen. There is an option to control the initial open/closed state of this section...

      Here is Tracy's README file from within the module settings page... 

       
      Make module authors start to think about how they can improve the change discovery process for their modules.
      There are notes in each of the sections displayed on the upgrade confirmation page that help authors use each of the features...

       
      Make sure display of external information doesn't introduce a vulnerability.
      This is an ongoing concern, and is the thing that is most likely to delay or prevent this module's release lead to this module's withdrawl should a vulnerability be found. Currently, output is formatted either via Markdown + HTML Purifier (if it was originally a Markdown file) or via htmlspecialchars() if it has come from a plaintext file.
      If you discover a vulnerability, please get in contact with me via the forum PM system.
       
      Ongoing...
      For now, I've concentrated on integration with GitHub, as most people use that platform to host their code. I know a few people are hosting their repositories with BitBucket (PWFoo comes to mind) and some with GitLab (Mike Rockett?) and I would eventually like to have adaptor implementations for these providers (and perhaps GitKraken) - but for now, GitHub rules and the other hosts are unsupported.
       
      Links
      Github: ModuleReleaseNotes
      PW Module Repository: Here
    • By FrancisChung
      Hi,
      I was wondering if anyone knew what this did? 

      If so, do you know what modules it actually impacts? Is there another log that lists the action it took?

      I'm having some weird problems with PHP duplicate declaration per link below, since this module was run.
       
       
    • By tpr
      AdminOnSteroids
      Various admin tweaks to enhance ProcessWire admin.
      http://modules.processwire.com/modules/admin-on-steroids/
      https://github.com/rolandtoth/AdminOnSteroids

    • By Macrura
      Field Descriptions Extended
      This module enables you to extend field descriptions by dividing short descriptions with a longer text that is revealed in a toggle.
      Github: https://github.com/outflux3/FieldDescriptionsExtended
      Extending your field descriptions using the standard field's description field.
      Once this module is installed, it will automatically search your description field for the presence of 5 dashes (-----).
      Any content above the 5 dashes will be visible and the content below the dashes will be hidden. A 'More...' link will appear at the end of the short description which when clicked will reveal the rest of the description.
      Using Simple Markdown Editor with the description field
      If you have Simple Markdown Editor (InputfieldSimpleMDE) installed, you can enable the field description to have that editor.
      *When using Simple MDE, you can use the button (Insert Horizontal Line) instead of typing 5 dashes. More about SimpleMDE.
      Extending your field descriptions using content from a ProcessWire Page for the field description.
      You may use the content from a ProcessWire page as a field description. This would allow you to easily insert images, links, and use hanna codes.
      To use page content for your field descriptions, please follow these instructions:
      Install Select Fields module (FieldtypeFields) http://modules.processwire.com/modules/fieldtype-fields/ Create a new field using this field type, e.g. field_select. Add the field to any template you will be using for your field descriptions. Setup your help pages (for example under a settings branch) where you will store the field description content,using the template containing the Field Select. Add content to a page and select the field where that content should show. To show a short text before the link to the longer content, separate them with 5 dashes Be sure to update your settings on this page, first enable page content descriptions,then specify the name of the Select Fields field, template to search, and content field. If you create a field description using this method, please note that the description field must be blank for contexts where you want the page content to appear.
      You can freely use template context for field descriptions, but the Page Content method is not context sensitive and will display under all contexts where the description is blank.
      ----
      original post:
      This is a new module, hope to release soon, which allows extended field descriptions, in currently 2 ways.
      The main feature of the module is that you can have a short description and then a 'more...' link which drops down a longer block of text.
      This is achieved by separating the intro/visible text and the rest with 5 dashes.

      Example setup:

      the 2nd way is if you are using AdminThemeUiKit, you can show extended field instructions in a panel. The content of the panel is edited on a regular PW page. This use case would probably not be that common, but if you had a field that required some extended instructions for how to use, this could be useful; Also, since this allows you to target information and instructions down at the field level, it could reduce the amount of documentation needed on a global level, since it is a lot more context targeted.