Skip to content

Commit

Permalink
Move FormHelper::_domId() to IdGeneratorTrait.
Browse files Browse the repository at this point in the history
  • Loading branch information
ADmad committed Mar 9, 2014
1 parent 218de22 commit ac25629
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
13 changes: 3 additions & 10 deletions src/View/Helper/FormHelper.php
Expand Up @@ -29,6 +29,7 @@
use Cake\View\Helper\StringTemplateTrait;
use Cake\View\StringTemplate;
use Cake\View\View;
use Cake\View\Widget\IdGeneratorTrait;
use Cake\View\Widget\WidgetRegistry;
use DateTime;
use Traversable;
Expand All @@ -43,6 +44,8 @@
*/
class FormHelper extends Helper {

use IdGeneratorTrait;

use StringTemplateTrait;

/**
Expand Down Expand Up @@ -708,16 +711,6 @@ public function label($fieldName, $text = null, $options = array()) {
return $this->widget('label', $attrs);
}

/**
* Generate an ID suitable for use in an ID attribute.
*
* @param string $value The value to convert into an ID.
* @return string The generated id.
*/
protected function _domId($value) {
return mb_strtolower(Inflector::slug($value, '-'));
}

/**
* Generate a set of inputs for `$fields`. If $fields is null the fields of current model
* will be used.
Expand Down
16 changes: 14 additions & 2 deletions src/View/Widget/IdGeneratorTrait.php
Expand Up @@ -39,7 +39,7 @@ protected function _clearIds() {
}

/**
* Generate an ID attribute for a radio button.
* Generate an ID attribute for an element.
*
* Ensures that id's for a given set of fields are unique.
*
Expand All @@ -48,7 +48,8 @@ protected function _clearIds() {
* @return string Generated id.
*/
protected function _id($name, $val) {
$name = mb_strtolower(Inflector::slug($name, '-'));
$name = $this->_domId($name);

$idSuffix = mb_strtolower(str_replace(array('/', '@', '<', '>', ' ', '"', '\''), '-', $val));
$count = 1;
$check = $idSuffix;
Expand All @@ -58,4 +59,15 @@ protected function _id($name, $val) {
$this->_idSuffixes[] = $check;
return trim($name . '-' . $check, '-');
}

/**
* Generate an ID suitable for use in an ID attribute.
*
* @param string $value The value to convert into an ID.
* @return string The generated id.
*/
protected function _domId($value) {
return mb_strtolower(Inflector::slug($value, '-'));
}

}

0 comments on commit ac25629

Please sign in to comment.