From 3e1c567f083f22b2beed15f61347ad41e6eca2ab Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 3 Jan 2012 21:07:22 -0500 Subject: [PATCH] Remove duplicate methods. Fix regression where #1345 was re-introduced. Fixes #2434 --- .../Test/Case/View/Helper/HtmlHelperTest.php | 4 + lib/Cake/View/Helper.php | 6 +- lib/Cake/View/Helper/HtmlHelper.php | 89 ------------------- 3 files changed, 7 insertions(+), 92 deletions(-) diff --git a/lib/Cake/Test/Case/View/Helper/HtmlHelperTest.php b/lib/Cake/Test/Case/View/Helper/HtmlHelperTest.php index 5c3844eb3..80e018d34 100644 --- a/lib/Cake/Test/Case/View/Helper/HtmlHelperTest.php +++ b/lib/Cake/Test/Case/View/Helper/HtmlHelperTest.php @@ -1521,6 +1521,10 @@ class HtmlHelperTest extends CakeTestCase { } $this->assertEquals($helper->parseAttributes(array('compact')), ' compact="compact"'); + $attrs = array('class' => array('foo', 'bar')); + $expected = ' class="foo bar"'; + $this->assertEquals(' class="foo bar"', $helper->parseAttributes($attrs)); + $helper = new Html5TestHelper($this->View); $expected = ' require'; $this->assertEquals($helper->parseAttributes(array('require')), $expected); diff --git a/lib/Cake/View/Helper.php b/lib/Cake/View/Helper.php index ade59beec..3e3270221 100644 --- a/lib/Cake/View/Helper.php +++ b/lib/Cake/View/Helper.php @@ -356,7 +356,7 @@ class Helper extends Object { * @param string $insertBefore String to be inserted before options. * @param string $insertAfter String to be inserted after options. * @return string Composed attributes. - * @deprecated This method has been moved to HtmlHelper + * @deprecated This method will be moved to HtmlHelper in 3.0 */ protected function _parseAttributes($options, $exclude = null, $insertBefore = ' ', $insertAfter = null) { if (!is_string($options)) { @@ -390,12 +390,12 @@ class Helper extends Object { * @param string $value The value of the attribute to create. * @param boolean $escape Define if the value must be escaped * @return string The composed attribute. - * @deprecated This method has been moved to HtmlHelper + * @deprecated This method will be moved to HtmlHelper in 3.0 */ protected function _formatAttribute($key, $value, $escape = true) { $attribute = ''; if (is_array($value)) { - $value = ''; + $value = implode(' ' , $value); } if (is_numeric($key)) { diff --git a/lib/Cake/View/Helper/HtmlHelper.php b/lib/Cake/View/Helper/HtmlHelper.php index 1396922e2..dd5157d3d 100644 --- a/lib/Cake/View/Helper/HtmlHelper.php +++ b/lib/Cake/View/Helper/HtmlHelper.php @@ -1029,93 +1029,4 @@ class HtmlHelper extends AppHelper { return $configs; } -/** - * Returns a space-delimited string with items of the $options array. If a - * key of $options array happens to be one of: - * - * - 'compact' - * - 'checked' - * - 'declare' - * - 'readonly' - * - 'disabled' - * - 'selected' - * - 'defer' - * - 'ismap' - * - 'nohref' - * - 'noshade' - * - 'nowrap' - * - 'multiple' - * - 'noresize' - * - * And its value is one of: - * - * - '1' (string) - * - 1 (integer) - * - true (boolean) - * - 'true' (string) - * - * Then the value will be reset to be identical with key's name. - * If the value is not one of these 3, the parameter is not output. - * - * 'escape' is a special option in that it controls the conversion of - * attributes to their html-entity encoded equivalents. Set to false to disable html-encoding. - * - * If value for any option key is set to `null` or `false`, that option will be excluded from output. - * - * @param array $options Array of options. - * @param array $exclude Array of options to be excluded, the options here will not be part of the return. - * @param string $insertBefore String to be inserted before options. - * @param string $insertAfter String to be inserted after options. - * @return string Composed attributes. - */ - protected function _parseAttributes($options, $exclude = null, $insertBefore = ' ', $insertAfter = null) { - if (is_array($options)) { - $options = array_merge(array('escape' => true), $options); - - if (!is_array($exclude)) { - $exclude = array(); - } - $filtered = array_diff_key($options, array_merge(array_flip($exclude), array('escape' => true))); - $escape = $options['escape']; - $attributes = array(); - - foreach ($filtered as $key => $value) { - if ($value !== false && $value !== null) { - $attributes[] = $this->_formatAttribute($key, $value, $escape); - } - } - $out = implode(' ', $attributes); - } else { - $out = $options; - } - return $out ? $insertBefore . $out . $insertAfter : ''; - } - -/** - * Formats an individual attribute, and returns the string value of the composed attribute. - * Works with minimized attributes that have the same value as their name such as 'disabled' and 'checked' - * - * @param string $key The name of the attribute to create - * @param string $value The value of the attribute to create. - * @param boolean $escape Define if the value must be escaped - * @return string The composed attribute. - */ - protected function _formatAttribute($key, $value, $escape = true) { - $attribute = ''; - if (is_array($value)) { - $value = ''; - } - - if (is_numeric($key)) { - $attribute = sprintf($this->_minimizedAttributeFormat, $value, $value); - } elseif (in_array($key, $this->_minimizedAttributes)) { - if ($value === 1 || $value === true || $value === 'true' || $value === '1' || $value == $key) { - $attribute = sprintf($this->_minimizedAttributeFormat, $key, $key); - } - } else { - $attribute = sprintf($this->_attributeFormat, $key, ($escape ? h($value) : $value)); - } - return $attribute; - } - }