Skip to content
Permalink
Browse files

Move FormHelper::_domId() to IdGeneratorTrait.

  • Loading branch information...
ADmad committed Mar 9, 2014
1 parent 218de22 commit ac25629fd0b112b62032e3e19fa2b44d8ad5e306
Showing with 17 additions and 12 deletions.
  1. +3 −10 src/View/Helper/FormHelper.php
  2. +14 −2 src/View/Widget/IdGeneratorTrait.php
@@ -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;
@@ -43,6 +44,8 @@
*/
class FormHelper extends Helper {
use IdGeneratorTrait;
use StringTemplateTrait;
/**
@@ -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.
@@ -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.
*
@@ -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;
@@ -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.
You can’t perform that action at this time.