Author: pmacadden
Date: 2010-09-03 18:55:18 +0200 (Fri, 03 Sep 2010)
New Revision: 30822
Added:
plugins/dcReloadedFormExtraPlugin/trunk/lib/widget/mtWidgetFormPlain.php
Log:
mtWidgetFormPlain widget added.
Added: plugins/dcReloadedFormExtraPlugin/trunk/lib/widget/mtWidgetFormPlain.php
===================================================================
--- plugins/dcReloadedFormExtraPlugin/trunk/lib/widget/mtWidgetFormPlain.php
(rev 0)
+++ plugins/dcReloadedFormExtraPlugin/trunk/lib/widget/mtWidgetFormPlain.php
2010-09-03 16:55:18 UTC (rev 30822)
@@ -0,0 +1,68 @@
+<?php
+
+/**
+ * mtWidgetFormPlainText represents text. It fetches this text using the
specified object and method.
+ *
+ * Options:
+ * * empty_value: A string to show when the value of the field is null.
+ * * value_callback: A valid Callback that should be used in order to obtain
a string value for the field.
+ * * add_hidden_input: if this is to true, a hidden input will be added.
+ * * use_retrieved_value: if this is set to false, the hidden input's value
will be set to the render's $value parameter.
+ *
+ * @author mtorres & ideas stolen from ncuesta
+ */
+class mtWidgetFormPlain extends sfWidgetForm
+{
+ public function __construct($options = array(), $attributes = array())
+ {
+ $this->addOption('object');
+ $this->addOption('method', '__toString');
+ $this->addOption('method_args', null);
+ $this->addOption('use_retrieved_value', true);
+ $this->addOption('empty_value', ' ');
+ $this->addOption('add_hidden_input', false);
+ $this->addOption('value_callback', null);
+
+ parent::__construct($options, $attributes);
+ }
+
+ public function render($name, $value = null, $attributes = array(), $errors
= array())
+ {
+ sfContext::getInstance()->getConfiguration()->loadHelpers(array('I18N'));
+ $original_value = $value;
+ if (!is_null($this->getOption('object')))
+ {
+ $args=$this->getOption('method_args');
+ if (is_null($args))
+ {
+ $value = call_user_func(array($this->getOption('object'),
$this->getOption('method')));
+ }
+ else
+ { $args=is_array($args)?$args:array($args);
+ $value = call_user_func_array(array($this->getOption('object'),
$this->getOption('method')),$args);
+ }
+ }
+
+ if (!is_null($this->getOption('value_callback')))
+ {
+ $string_value = call_user_func($this->getOption('value_callback'),
$value);
+ }
+ else
+ {
+ $string_value = $value;
+ }
+
+ $html = '';
+ if ($this->getOption('add_hidden_input'))
+ {
+ $val = $this->getOption('use_retrieved_value')? $value : $original_value;
+ $input_hidden = new sfWidgetFormInputHidden(array(), $attributes);
+ $html .= $input_hidden->render($name, $val);
+ }
+
+ $text = is_null($value) ? __($this->getOption('empty_value')) :
$string_value;
+ $html .= '<span id="'.$this->generateId($name.'_description',
$value).'">'.$text.'</span>';
+
+ return $html;
+ }
+}
--
You received this message because you are subscribed to the Google Groups
"symfony SVN" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/symfony-svn?hl=en.