Use custom frozen template see BT#11194

pull/2487/head
jmontoyaa 9 years ago
parent 3df995697e
commit 879d1ffefe
  1. 5
      main/inc/lib/pear/HTML/QuickForm.php
  2. 6
      main/inc/lib/pear/HTML/QuickForm/Renderer/Default.php
  3. 68
      main/inc/lib/pear/HTML/QuickForm/element.php
  4. 2
      main/inc/lib/pear/HTML/QuickForm/input.php
  5. 2
      main/inc/lib/pear/HTML/QuickForm/text.php
  6. 8
      main/inc/lib/usermanager.lib.php

@ -1582,7 +1582,7 @@ class HTML_QuickForm extends HTML_Common
* @access public * @access public
* @throws HTML_QuickForm_Error * @throws HTML_QuickForm_Error
*/ */
public function freeze($elementList=null) public function freeze($elementList = null, $setTemplateFrozen = '')
{ {
if (!isset($elementList)) { if (!isset($elementList)) {
$this->_freezeAll = true; $this->_freezeAll = true;
@ -1597,6 +1597,9 @@ class HTML_QuickForm extends HTML_Common
foreach (array_keys($this->_elements) as $key) { foreach (array_keys($this->_elements) as $key) {
$name = $this->_elements[$key]->getName(); $name = $this->_elements[$key]->getName();
if ($this->_freezeAll || isset($elementList[$name])) { if ($this->_freezeAll || isset($elementList[$name])) {
if (!empty($setTemplateFrozen)) {
$this->_elements[$key]->setCustomFrozenTemplate($setTemplateFrozen);
}
$this->_elements[$key]->freeze(); $this->_elements[$key]->freeze();
unset($elementList[$name]); unset($elementList[$name]);
} }

@ -303,6 +303,12 @@ class HTML_QuickForm_Renderer_Default extends HTML_QuickForm_Renderer
$template = $element->getTemplate( $template = $element->getTemplate(
$this->getForm()->getLayout() $this->getForm()->getLayout()
); );
if ($element->isFrozen()) {
$customFrozentemplate = $element->getCustomFrozenTemplate();
if (!empty($customFrozentemplate)) {
$template = $customFrozentemplate;
}
}
} else { } else {
$template = $this->getForm()->getDefaultElementTemplate(); $template = $this->getForm()->getDefaultElementTemplate();
} }

@ -1,6 +1,4 @@
<?php <?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/** /**
* Base class for form elements * Base class for form elements
* *
@ -39,8 +37,8 @@ class HTML_QuickForm_element extends HTML_Common
{ {
private $layout; private $layout;
private $icon; private $icon;
private $template;
// {{{ properties private $customFrozenTemplate = '';
/** /**
* Label of the field * Label of the field
@ -87,9 +85,9 @@ class HTML_QuickForm_element extends HTML_Common
* @param string Name of the element * @param string Name of the element
* @param mixed Label(s) for the element * @param mixed Label(s) for the element
* @param mixed Associative array of tag attributes or HTML attributes name="value" pairs * @param mixed Associative array of tag attributes or HTML attributes name="value" pairs
* @since 1.0 * @since 1.0
* @access public * @access public
* @return void * @return void
*/ */
public function __construct($elementName = null, $elementLabel = null, $attributes = null) public function __construct($elementName = null, $elementLabel = null, $attributes = null)
{ {
@ -98,8 +96,7 @@ class HTML_QuickForm_element extends HTML_Common
$this->setName($elementName); $this->setName($elementName);
} }
if (isset($elementLabel)) { if (isset($elementLabel)) {
$labelFor = '';
$labelFor = "";
// Default Inputs generate this // Default Inputs generate this
if (!empty($attributes['id'])) { if (!empty($attributes['id'])) {
$labelFor = $attributes['id']; $labelFor = $attributes['id'];
@ -159,7 +156,7 @@ class HTML_QuickForm_element extends HTML_Common
* @access public * @access public
* @return float * @return float
*/ */
function apiVersion() public function apiVersion()
{ {
return 3.2; return 3.2;
} // end func apiVersion } // end func apiVersion
@ -174,7 +171,7 @@ class HTML_QuickForm_element extends HTML_Common
* @access public * @access public
* @return string * @return string
*/ */
function getType() public function getType()
{ {
return $this->_type; return $this->_type;
} // end func getType } // end func getType
@ -190,7 +187,7 @@ class HTML_QuickForm_element extends HTML_Common
* @access public * @access public
* @return void * @return void
*/ */
function setName($name) public function setName($name)
{ {
// interface method // interface method
} //end func setName } //end func setName
@ -205,7 +202,7 @@ class HTML_QuickForm_element extends HTML_Common
* @access public * @access public
* @return string * @return string
*/ */
function getName() public function getName()
{ {
// interface method // interface method
} //end func getName } //end func getName
@ -221,7 +218,7 @@ class HTML_QuickForm_element extends HTML_Common
* @access public * @access public
* @return void * @return void
*/ */
function setValue($value) public function setValue($value)
{ {
// interface // interface
} // end func setValue } // end func setValue
@ -236,7 +233,7 @@ class HTML_QuickForm_element extends HTML_Common
* @access public * @access public
* @return mixed * @return mixed
*/ */
function getValue() public function getValue()
{ {
// interface // interface
return null; return null;
@ -251,7 +248,7 @@ class HTML_QuickForm_element extends HTML_Common
* @access public * @access public
* @return void * @return void
*/ */
function freeze() public function freeze()
{ {
$this->_flagFrozen = true; $this->_flagFrozen = true;
} //end func freeze } //end func freeze
@ -266,7 +263,7 @@ class HTML_QuickForm_element extends HTML_Common
* @return void * @return void
* @since 3.2.4 * @since 3.2.4
*/ */
function unfreeze() public function unfreeze()
{ {
$this->_flagFrozen = false; $this->_flagFrozen = false;
} }
@ -294,9 +291,6 @@ class HTML_QuickForm_element extends HTML_Common
// //
} //end func getFrozenHtml } //end func getFrozenHtml
// }}}
// {{{ _getPersistantData()
/** /**
* Used by getFrozenHtml() to pass the element's value if _persistantFreeze is on * Used by getFrozenHtml() to pass the element's value if _persistantFreeze is on
* *
@ -552,4 +546,38 @@ class HTML_QuickForm_element extends HTML_Common
} }
} }
} }
/**
* @param mixed $template
* @return HTML_QuickForm_element
*/
public function setTemplate($template)
{
$this->template = $template;
return $this;
}
/**
* @return string
*/
public function getCustomFrozenTemplate()
{
return $this->customFrozenTemplate;
}
/**
* @param string $customFrozenTemplate
* @return HTML_QuickForm_element
*/
public function setCustomFrozenTemplate($customFrozenTemplate)
{
$this->customFrozenTemplate = $customFrozenTemplate;
return $this;
}
} }

@ -143,7 +143,7 @@ class HTML_QuickForm_input extends HTML_QuickForm_element
*/ */
public function toHtml() public function toHtml()
{ {
if ($this->_flagFrozen) { if ($this->isFrozen()) {
return $this->getFrozenHtml(); return $this->getFrozenHtml();
} else { } else {
return $this->_getTabs() . '<input' . $this->_getAttrString($this->_attributes) . ' />'; return $this->_getTabs() . '<input' . $this->_getAttrString($this->_attributes) . ' />';

@ -235,7 +235,7 @@ class HTML_QuickForm_text extends HTML_QuickForm_input
*/ */
public function toHtml() public function toHtml()
{ {
if ($this->_flagFrozen) { if ($this->isFrozen()) {
return $this->getFrozenHtml(); return $this->getFrozenHtml();
} else { } else {
return '<input ' . $this->_getAttrString($this->_attributes) . ' />'; return '<input ' . $this->_getAttrString($this->_attributes) . ' />';

@ -477,6 +477,14 @@ class UserManager
// variables for the default template // variables for the default template
$tplContent->assign('complete_name', stripslashes(api_get_person_name($firstName, $lastName))); $tplContent->assign('complete_name', stripslashes(api_get_person_name($firstName, $lastName)));
$tplContent->assign('user_added', $user); $tplContent->assign('user_added', $user);
$renderer = FormValidator::getDefaultRenderer();
// Form template
$elementTemplate = ' {label}: {element} <br />';
$renderer->setElementTemplate($elementTemplate);
$form->freeze(null, $elementTemplate);
/** @var FormValidator $form */ /** @var FormValidator $form */
$form->freeze(); $form->freeze();
$form->removeElement('submit'); $form->removeElement('submit');

Loading…
Cancel
Save