Jump to content
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

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By teppo
      MarkupMenu is a markup module for generating menu trees. When provided a root page as a starting point, it generates a navigation tree (by default as a HTML "<ul>" element wrapped by a "<nav>" element) from that point onwards. If you've also provided it with current (active) page, the menu will be rendered accordingly, with current item highlighted and items rendered up to that item and its children (unless you disable the "collapsed" option, in which case the full page tree will be rendered instead).
      Modules directory: https://modules.processwire.com/modules/markup-menu/ GitHub repository: https://github.com/teppokoivula/MarkupMenu Usage
      As a markup module, MarkupMenu is intended for front-end use, but you can of course use it in a module as well. Typically you'll only need the render() method, which takes an array of options as its only argument:
      echo $modules->get('MarkupMenu')->render([ 'root_page' => $pages->get(1), 'current_page' => $page, ]); Note: if you omit root_page, site root page is used by default. If you omit current_page, the menu will be rendered, but current (active) page won't be highlighted etc.
      A slightly more complex example, based on what I'm using on one of my own sites to render a (single-level) top menu:
      echo $modules->get('MarkupMenu')->render([ 'current_page' => $page, 'templates' => [ 'nav' => '<nav class="{classes} menu--{menu_class_modifier}" aria-label="{aria_label}">%s</nav>', 'item_current' => '<a class="menu__item menu__item--current" href="{item.url}" tabindex="0" aria-label="Current page: {item.title}">{item.title}</a>', ], 'placeholders' => [ 'menu_class_modifier' => 'top', 'aria_label' => 'Main navigation', ], 'include' => [ 'root_page' => true, ], 'exclude' => [ 'level_greater_than' => 1, ], ]); Note: some things you see above may not be entirely sensible, such as the use of {menu_class_modifier} and {aria_label} placeholders. On the actual site the "nav" template is defined in site config, so I can define just these parts on a case-by-case basis while actual nav markup is maintained in one place.
      Please check out the README file for available render options. I'd very much prefer not to keep this list up to date in multiple places. Basically there are settings for defining "templates" for different parts of the menu (list, item, etc.), include array for defining rules for including in the menu and exclude array for the opposite effect, classes and placeholders arrays for overriding default classes and injecting custom placeholders, etc. 🙂
      MarkupMenu vs. MarkupSimpleNavigation
      TL;DR: this is another take on the same concept. There are many similarities, but also some differences – especially when it comes to the supported options and syntax. If you're currently using MarkupSimpleNavigation then there's probably no reason to switch over.
      I'd be surprised if anyone didn't draw lines between this module and Soma's awesome MarkupSimpleNavigation. Simply put, I've been using MSN (...) for a number of years, and it's been great – but there have been some smallish issues with it, particularly with the markup generation part, and it's also doing some things in a way that just doesn't work for me – the xtemplates thing being one of these. In many ways it's less about features, and more about style.
      In MarkupMenu I've tried to correct these little hiccups, modernise the default markup, and allow for more flexibility with placeholder variables and additional / different options. MarkupMenu was built for ProcessWire 3.0.112+ and PHP 7.1+, it's installable with Composer, and I have a few additional ideas (such as conditional placeholders) on my todo list.
      One smallish and rather specific difference is that MarkupMenu supports overriding default options via $config->MarkupMenu. I find myself redefining the default markup for every site, which until now meant that each site has a wrapper function for MarkupSimpleNavigation (to avoid code / config repetition), and this way I've been able to omit that 🙂
      Requirements
      ProcessWire >= 3.0.112 PHP >= 7.1.0 If you're working on an earlier version of ProcessWire or PHP, use MarkupSimpleNavigation instead.
    • By Robin S
      Repeater Images
      Adds options to modify Repeater fields to make them convenient for "page-per-image" usage. Using a page-per-image approach allows for additional fields to be associated with each image, to record things such as photographer, date, license, links, etc.
      When Repeater Images is enabled for a Repeater field the module changes the appearance of the Repeater inputfield to be similar (but not identical) to an Images field. The collapsed view shows a thumbnail for each Repeater item, and items can be expanded for field editing.
      Screencast

      Installation
      Install the Repeater Images module.
      Setup
      Create an image field to use in the Repeater field. Recommended settings for the image field are "Maximum files allowed" set to 1 and "Formatted value" set to "Single item (null if empty)". Create a Repeater field. Add the image field to the Repeater. If you want additional fields in the Repeater create and add these also. Repeater Images configuration
      Tick the "Activate Repeater Images for this Repeater field" checkbox. In the "Image field within Repeater" dropdown select the single image field. You must save the Repeater field settings to see any newly added Image fields in the dropdown. Adjust the image thumbnail height if you want (unlike the core Images field there is no slider to change thumbnail height within Page Edit). Note: the depth option for Repeater fields is not compatible with the Repeater Images module.
      Image uploads feature
      There is a checkbox to activate image uploads. This feature allows users to quickly and easily add images to the Repeater Images field by uploading them to an adjacent "upload" field.
      To use this feature you must add the image field selected in the Repeater Images config to the template of the page containing the Repeater Images field - immediately above or below the Repeater Images field would be a good position.
      It's recommended to set the label for this field in template context to "Upload images" or similar, and set the visibility of the field to "Closed" so that it takes up less room when it's not being used. Note that when you drag images to a closed Images field it will automatically open. You don't need to worry about the "Maximum files allowed" setting because the Repeater Images module overrides this for the upload field.
      New Repeater items will be created from the images uploaded to the upload field when the page is saved. The user can add descriptions and tags to the images while they are still in the upload field and these will be retained in the Repeater items. Images are automatically deleted from the upload field when the page is saved.
      Tips
      The "Use accordion mode?" option in the Repeater field settings is useful for keeping the inputfield compact, with only one image item open for editing at a time. The "Repeater item labels" setting determines what is shown in the thumbnail overlay on hover. Example for an image field named "image": {image.basename} ({image.width}x{image.height})  
      https://github.com/Toutouwai/RepeaterImages
      https://modules.processwire.com/modules/repeater-images/
    • By EyeDentify
      Hello There Guys.

      I am in the process of getting into making my first modules for PW and i had a question for you PHP and PW gurus in here.

      I was wondering how i could use an external library, lets say TwitterOAuth in my PW module.
      Link to library
      https://twitteroauth.com/

      Would the code below be correct or how would i go about this:
      <?PHP namespace ProcessWire; /* load the TwitterOAuth library from my Module folder */ require "twitteroauth/autoload.php"; use Abraham\TwitterOAuth\TwitterOAuth; class EyeTwitter extends WireData,TwitterOAuth implements Module { /* vars */ protected $twConnection; /* extend parent TwitterOAuth contructor $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token, $access_token_secret); */ public function myTwitterConnection ($consumer_key, $consumer_secret, $access_token, $access_token_secret) { /* save the connection for use later */ $this->twConnection = TwitterOAuth::__construct($consumer_key, $consumer_secret, $access_token, $access_token_secret); } } ?> Am i on the right trail here or i am barking up the wrong tree?
      I don´t need a complete solution, i just wonder if i am including the external library the right way.
      If not, then give me a few hint´s and i will figure it out.

      Thanks a bunch.

      /EyeDentify
    • By dimitrios
      Hello,
      this module can publish content of a Processwire page on a Facebook page, triggered by saving the Processwire page.
      To set it up, configure the module with a Facebook app ID, secret and a Page ID. Following is additional configuration on Facebook for developers:
      Minimum Required Facebook App configuration:
      on Settings -> Basics, provide the App Domains, provide the Site URL, on Settings -> Advanced, set the API version (has been tested up to v3.3), add Product: Facebook Login, on Facebook Login -> Settings, set Client OAuth Login: Yes, set Web OAuth Login: Yes, set Enforce HTTPS: Yes, add "http://www.example.com/processwire/page/" to field Valid OAuth Redirect URIs. This module is configurable as follows:
      Templates: posts can take place only for pages with the defined templates. On/Off switch: specify a checkbox field that will not allow the post if checked. Specify a message and/or an image for the post.
      Usage
      edit the desired PW page and save; it will post right after the initial Facebook log in and permission granting. After that, an access token is kept.
       
      Download
      PW module directory: http://modules.processwire.com/modules/auto-fb-post/ Github: https://github.com/kastrind/AutoFbPost   Note: Facebook SDK for PHP is utilized.


    • By kongondo
      Media Manager
       
      Released 31 March 2016
      https://processwireshop.pw/plugins/media-manager/
      Documentation 
      http://mediamanager.kongondo.com/
      As of 10 May 2019 ProcessWire versions earlier than 3.x are not supported
      *******************************************************   ORIGINAL POST   *******************************************************
      API Example (frontend; will be added to documentation site)
      Accessing and outputting the contents of the MediaManager field(s) in your template is quite simple. The fields are accessed like many other ProcessWire fields. The fields return an array of type MediaManagerArray that need to be looped to output each media within. Assuming you created a field of type MediaManager named 'media', you can loop through it for a given page as shown below.
        @note: Each MediaManager object has the following 5 basic properties:   DATABASE (saved properties) 1. id => pageID of the page where the media lives (hidden in admin and not important to know about) 2. type => integer denoting media type (1=audio; 2=document; 3=image [for variations this will be 3x, where x is the number of the variation of an original image]; 4=video)   RUNTIME 3. typeLabel => user friendly string denoting media type (audio, document, image, video) 4. media => a ProcessWire Image/File Object including all their properties (ext, filesizeStr, height, width, description, tags, filename, basename, etc.) 5. title => title of media (@note: this is the title of the page where the media lives; may or may not be the same as the name of the media file itself). This can be used as a user-friendly name for your media $media = $page->media;// returns a MediaManagerArray. Needs to be looped through foreach ($media as $m) { echo $m->id;// e.g. 1234 (hidden page in /admin/media-manager/media-parent/) echo $m->type;// e.g. 3 (a media of type image) OR 1 (a media of type audio) echo $m->typeLabel;// e.g. 'document' (i.e. type would be 2) echo $m->title;// e.g. 'My Nice Trip' (whose media file could be my-nice-trip.mp4) /* @note: - $m->media returns an object; either a ProcessWire Image (for image media) or File object (for audio, document and video media) - This means you have access to all the properties of that object, e.g. ext, tags, description, url, filename, basename, width, height, modified, created, filesize, filesizeStr, etc as well as associated methods, e.g. size() */ echo $m->media->tags; } // only output images foreach ($media as $m) { if($m->typeLabel =='image') { echo "<img src='" . $m->media->size(100,75)->url . "'><br>"; } } // There's also a toString() method so you can do: echo $page->media; /* All your media will be output wrapped in appropriate HTML tags, i.e.: audio: <audio></audio>; document: <a></a>; image: <img>; video: <video></video>; */  
      *******************************************************   ORIGINAL POST   *******************************************************
       
      The topic of a central media manager feature for ProcessWire has come up several times:
       
      https://processwire.com/talk/topic/4330-get-image-from-other-pages-via-images-field/
      https://processwire.com/talk/topic/4330-get-image-from-other-pages-via-images-field/?p=42578
      https://processwire.com/talk/topic/4330-get-image-from-other-pages-via-images-field/?p=42582
      https://processwire.com/talk/topic/425-file-manager/
      https://processwire.com/talk/topic/425-file-manager/?p=13802
      https://processwire.com/talk/topic/425-file-manager/?p=13861
      https://processwire.com/talk/topic/10763-asset-manager-asset-selector/
       
      More recently, regarding my Visual Page Selector module, I have been asked several times why the module does not have an in-built feature to upload images.
       
      There's two camps on the topic of a central media manager: those who like them (especially those coming in to PW from other CMSes) and those who don't like them (primarily because of the chaotic way some CMSes (dis)organise their media management) . I think that we can have our cake and eat it too! If done the right way, closely following the principles of and harnessing the power of ProcessWire, we can have a well-implemented, organised, feature-rich, site-wide media manager.
       
      Introducing Media Manager: (a commercial module)
       
      Alongside a number of modules I am currently working on (both free and commercial), I have been developing  a centralised Media Manager for ProcessWire. Before you cast the first stone, no, this is not going to be a one-large-media-bucket as in other CMS where it gets very messy very quickly . In the backend things are neatly stored away, yes, in pages. However, those are pages you will not see (just like repeater pages). Before anyone has a go at pages, remember a page is not that thing you see on the ProcessWire Tree (that's just its visual representation); A page is a record/row in the database    . For the end-user of Media Manager, all they will see is the 'familiar media bucket' to select their media from. As long as it works efficiently, I don't think they care about the wizardry behind the scenes  . 
       
      The module allows for the comprehensive management of several media types:
      Audio Video Images Documents Each media type will be handled by its own sub-module so the user can pick and install/choose the type of media management they want.
       
      Features include:
      Access controls Centralized uploads of media Bulk management of media: tag, delete, describe, replace, etc. Bulk upload: zip; scan, single Quick upload in page edit mode Usage stats across pages (maybe?) Etc.. Would love to hear your thoughts and any feature suggestions. I think there's enough demand for such a module. If not, please let me know so that I can instead focus on other things  , thanks.
       
      How other CMS do it

       
      The more efficient (PW) way of doing it

×
×
  • Create New...