Make the cue that is being appended to required form elements configurable

refs #7934
This commit is contained in:
Johannes Meyer 2015-02-27 09:08:05 +01:00
parent 48c3199a2d
commit c00e336ea8
1 changed files with 32 additions and 2 deletions

View File

@ -119,6 +119,13 @@ class Form extends Zend_Form
*/
protected $protectIds = true;
/**
* The cue that is appended to each element's label if it's required
*
* @var string
*/
protected $requiredCue = '*';
/**
* Authentication manager
*
@ -406,6 +413,29 @@ class Form extends Zend_Form
return $this->protectIds;
}
/**
* Set the cue to append to each element's label if it's required
*
* @param string $cue
*
* @return Form
*/
public function setRequiredCue($cue)
{
$this->requiredCue = $cue;
return $this;
}
/**
* Return the cue being appended to each element's label if it's required
*
* @return string
*/
public function getRequiredCue()
{
return $this->requiredCue;
}
/**
* Create this form
*
@ -604,10 +634,10 @@ class Form extends Zend_Form
if ($element->isRequired() && strpos(strtolower($element->getType()), 'checkbox') === false) {
$element->setAttrib('aria-required', 'true'); // ARIA
$element->setAttrib('required', ''); // HTML5
if (($label = $element->getDecorator('label')) !== false) {
if (($cue = $this->getRequiredCue()) !== null && ($label = $element->getDecorator('label')) !== false) {
$element->setLabel($this->getView()->escape($element->getLabel()));
$label->setOption('escape', false);
$label->setOption('requiredSuffix', ' <span aria-hidden="true">*</span>');
$label->setOption('requiredSuffix', sprintf(' <span aria-hidden="true">%s</span>', $cue));
}
}