Pieforms attempts to load renderer plugin even when already loaded

Bug #1189823 reported by Luke Carrier
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Mahara
Expired
Low
Unassigned

Bug Description

This prevents plugins from providing their own form renderers (useful for working around issues like #1181966 -- nested fieldsets are broken).

I've attached a patch to the Pieforms library which changes the behaviour a little bit; if the renderer function already exists, we'll skip the loading process.

Revision history for this message
Luke Carrier (lukecarrier) wrote :
Revision history for this message
Andrew Nicols (dobedobedoh) wrote :

Cheers Luke,

That patch looks good to me.

Just to confirm, this is to work around issues where you wish to use a function which is defined outside of the pieforms structure and where the function has already been defined. Therefore it is not necessary (or appropriate) to include the file from the pieforms file structure.

Revision history for this message
Luke Carrier (lukecarrier) wrote :

That's correct, this patch ensures that functions defined outside of the Pieforms library (e.g. within Mahara plugins) can be sourced outside of Pieforms, and prevents Pieforms from unnecessarily attempting to include the containing file.

Revision history for this message
Mahara Bot (dev-mahara) wrote : A patch has been submitted for review

Patch for "master" branch: https://reviews.mahara.org/6017

Revision history for this message
Aaron Wells (u-aaronw) wrote :

Hi Luke,

Thanks for the patch! However, I don't think it's actually necessary. If your intent is, say, to load the file htdocs/pieforms/pieform/renderers/div.php so that you can call the method "pieform_renderer_div()" from within another function, then you can already do that. Pieform->include_plugin() uses "include_once()" rather than "include()", so it won't error our if the file gets double-included.

Or, if your intent is to tweak the behavior of one of the core renderers by duplicating the method "pieform_renderer_div()" inside another file, then the preferred way to achieve that would be to instead create an entirely new pieform renderer, called, e.g. "fancydiv". You can store this under your plugin's directories, and make pieform load it by adding this to your form definitions:

'configdirs' => array(get_config('docroot') . 'path/to/my/plugin/');

On the third hand, if you've made some improvements to a core renderer (like addressing the nested fieldsets issues), the recommended approach is to submit those changes for upstreaming. We'll try not to take 3 years on it next time. ;)

Cheers,
Aaron

Revision history for this message
Aaron Wells (u-aaronw) wrote :

Specifically, you'd need to alter configdirs *and* set the renderer:

$formdef = array(
    // ... other form definition stuff
    'configdirs' => array(get_config('docroot') . 'path/to/my/plugin/'),
    'renderer' => 'fancydiv',
);

$form = pieform($formdef);

Robert Lyon (robertl-9)
Changed in mahara:
milestone: 16.04.1 → 16.10.0
Robert Lyon (robertl-9)
Changed in mahara:
milestone: 16.10.0 → 16.10.1
Robert Lyon (robertl-9)
Changed in mahara:
milestone: 16.10.1 → 17.04.0
no longer affects: mahara/16.10
no longer affects: mahara/16.04
Changed in mahara:
assignee: Aaron Wells (u-aaronw) → nobody
milestone: 17.04.0 → none
Revision history for this message
Launchpad Janitor (janitor) wrote :

[Expired for Mahara because there has been no activity for 60 days.]

Changed in mahara:
status: Incomplete → Expired
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.