From: Gergő Tisza Date: Tue, 2 Aug 2016 07:27:44 +0000 (-0700) Subject: Allow closures as HTMLInfoField values X-Git-Tag: 1.31.0-rc.0~5935^2~1 X-Git-Url: http://git.cyclocoop.org//%22%22._DIR_PLUGIN_FULLCALENDAR.%22prive/themes/spip/images/event_edit.png/%22?a=commitdiff_plain;h=3cc87a8b1278078966ddf7870f7ac17620564a9d;p=lhc%2Fweb%2Fwiklou.git Allow closures as HTMLInfoField values This makes it possible to parametrize info fields so they can be easily altered. Change-Id: I17328cf3f1a710096c64b17dde0864cb9be3892d --- diff --git a/includes/htmlform/fields/HTMLInfoField.php b/includes/htmlform/fields/HTMLInfoField.php index ada4fb67c6..6dc5d08091 100644 --- a/includes/htmlform/fields/HTMLInfoField.php +++ b/includes/htmlform/fields/HTMLInfoField.php @@ -4,12 +4,29 @@ * An information field (text blob), not a proper input. */ class HTMLInfoField extends HTMLFormField { + /** + * @param array $info + * In adition to the usual HTMLFormField parameters, this can take the following fields: + * - default: the value (text) of the field. Unlike other form field types, HTMLInfoField can + * take a closure as a default value, which will be evaluated with $info as its only parameter. + * - raw: if true, the value won't be escaped. + * - rawrow: if true, the usual wrapping of form fields (e.g. into a table row + cell when + * display mode is table) will not happen and the value must contain it already. + */ public function __construct( $info ) { $info['nodata'] = true; parent::__construct( $info ); } + function getDefault() { + $default = parent::getDefault(); + if ( $default instanceof Closure ) { + $default = call_user_func( $default, $this->mParams ); + } + return $default; + } + public function getInputHTML( $value ) { return !empty( $this->mParams['raw'] ) ? $value : htmlspecialchars( $value ); }