Browse Source

Move FormHelper::_domId() to IdGeneratorTrait.

ADmad 12 years ago
parent
commit
ac25629fd0
2 changed files with 17 additions and 12 deletions
  1. 3 10
      src/View/Helper/FormHelper.php
  2. 14 2
      src/View/Widget/IdGeneratorTrait.php

+ 3 - 10
src/View/Helper/FormHelper.php

@@ -29,6 +29,7 @@ use Cake\View\Helper;
 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 @@ use Traversable;
  */
 class FormHelper extends Helper {
 
+	use IdGeneratorTrait;
+
 	use StringTemplateTrait;
 
 /**
@@ -709,16 +712,6 @@ class FormHelper extends Helper {
 	}
 
 /**
- * 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.
  *

+ 14 - 2
src/View/Widget/IdGeneratorTrait.php

@@ -39,7 +39,7 @@ trait IdGeneratorTrait {
 	}
 
 /**
- * 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 @@ trait IdGeneratorTrait {
  * @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 @@ trait IdGeneratorTrait {
 		$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, '-'));
+	}
+
 }