Feature proposal #2279
closedCB Substitutions: add default, output, formatting, reason options for fields and tab
Description
Having the option to specify specifically how to output and format from where a fields value would give much finer control. For example when substituting in Avatar it will always be full size and non-linked as the output, formatting, and reason are hardcoded in for Profile View. This limits substitution usage quite greatly.
Files
Updated by krileon almost 14 years ago
- File 2279.patch 2279.patch added
- Status changed from New to Resolved
- Assignee set to beat
- Target version set to CB 1.4.0
- % Done changed from 0 to 100
Added support to getTab for output, formatting, and reason. Extended REGEX to capture output="STRING", formatting="STRING", and reason="STRING". Test case as follows (confirmed working). Completely backwards compatible as the additional options are similar to user= and not required.
Without User:
[cb:userfield field="avatar" output="html" formatting="none" reason="list" /]
With User:
[cb:userfield field="avatar" user="#me" output="html" formatting="none" reason="list" /]
Any combination of user, output, formatting, or reason can be used as well. So all 3/4 are not required to be provided. You can simply provide just reason such as follows.
[cb:userfield field="avatar" reason="list" /]
Updated by krileon almost 14 years ago
- File 2279-rev2.patch 2279-rev2.patch added
Sorry, named $output as $display, makes more sense to be $output. Rev2 fixes this.
Updated by beat almost 14 years ago
- getField() has one more param: $defaultValue = null than the suggested tab implementation. We should become 100% coherent there with params.
- suggested getTab has default for $formatting = null the getField default $formatting is 'none'.
Updated by beat almost 14 years ago
- Subject changed from Substitutions: add output, formatting, reason options for fields to CB Substitutions: add default, output, formatting, reason options for fields and tab
- Status changed from Resolved to Closed
Thanks Kyle.
Implemented in r1424 with following changes:- added default="....." which displays when field or tab is not showed to user for any reason (access level, no user, and so on).
- added $default to getTab() API as well, to make it consistent with getField().
Probably the regexp could be changed as follows:
instead of:
#\[cb:user(data +field|field +field|tab +tab|position +position)="([a-zA-Z0-9_]+)"(?: +user="([^"/\] ]+)")?(?: +default="((?:[^"]|\\")+)")?(?: +output="([a-zA-Z]+)")?(?: +formatting="([a-zA-Z]+)")?(?: +reason="([a-zA-Z]+)")? */\]#
to something like this:
#\[cb:user(data +field|field +field|tab +tab|position +position)="([a-zA-Z0-9_]+)"(?: +(user|default|output|formatting|reason)="((?:[^"]|\\")+)")* */\]#
or even:
#\[cb:([^ ]+)(?: +(field|tab|position|user|default|output|formatting|reason|[a-zA-Z]+)="((?:[^"]|\\")+)")* */\]#
That would then allow to generalize the parser...and even make it fully extensible.
That is as forethought for related feature #2297