Skip to content

Commit

Permalink
Code cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
ADmad committed Feb 23, 2014
1 parent b7cf739 commit a87ef06
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 105 deletions.
97 changes: 3 additions & 94 deletions src/View/Helper/FormHelper.php
Expand Up @@ -302,7 +302,6 @@ public function create($model = null, $options = []) {
$append .= $this->hidden('_method', array(
'name' => '_method',
'value' => strtoupper($options['type']),
'id' => null,
'secure' => static::SECURE_SKIP
));
default:
Expand Down Expand Up @@ -1491,10 +1490,10 @@ public function button($title, $options = array()) {
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#FormHelper::postButton
*/
public function postButton($title, $url, $options = array()) {
$out = $this->create(false, array('id' => false, 'url' => $url));
$out = $this->create(false, array('url' => $url));
if (isset($options['data']) && is_array($options['data'])) {
foreach ($options['data'] as $key => $value) {
$out .= $this->hidden($key, array('value' => $value, 'id' => false));
$out .= $this->hidden($key, array('value' => $value));
}
unset($options['data']);
}
Expand Down Expand Up @@ -1551,7 +1550,6 @@ public function postLink($title, $url = null, $options = array(), $confirmMessag
$formOptions = array(
'action' => $this->url($url),
'name' => $formName,
'id' => $formName,
'style' => 'display:none;',
'method' => 'post',
);
Expand All @@ -1570,7 +1568,7 @@ public function postLink($title, $url = null, $options = array(), $confirmMessag
if (isset($options['data']) && is_array($options['data'])) {
foreach ($options['data'] as $key => $value) {
$fields[$key] = $value;
$out .= $this->hidden($key, array('value' => $value, 'id' => false));
$out .= $this->hidden($key, array('value' => $value));
}
unset($options['data']);
}
Expand Down Expand Up @@ -2208,95 +2206,6 @@ protected function _datetimeOptions($options) {
return $options;
}

/**
* Parse the value for a datetime selected value
*
* @param string|array $value The selected value.
* @param integer $timeFormat The time format
* @return array Array of selected value.
*/
protected function _getDateTimeValue($value, $timeFormat) {
$year = $month = $day = $hour = $min = $meridian = null;
if (is_array($value)) {
extract($value);
if ($meridian === 'pm') {
$hour += 12;
}
return array($year, $month, $day, $hour, $min, $meridian);
}

if (is_numeric($value)) {
$value = strftime('%Y-%m-%d %H:%M:%S', $value);
}
$meridian = 'am';
$pos = strpos($value, '-');
if ($pos !== false) {
$date = explode('-', $value);
$days = explode(' ', $date[2]);
$day = $days[0];
$month = $date[1];
$year = $date[0];
} else {
$days[1] = $value;
}

if (!empty($timeFormat)) {
$time = explode(':', $days[1]);

if ($time[0] >= 12) {
$meridian = 'pm';
}
$hour = $min = null;
if (isset($time[1])) {
$hour = $time[0];
$min = $time[1];
}
}
return array($year, $month, $day, $hour, $min, $meridian);
}

/**
* Gets the input field name for the current tag
*
* @param array $options
* @param string $field
* @param string $key
* @return array
*/
protected function _name($options = array(), $field = null, $key = 'name') {
if ($this->requestType === 'get') {
if ($options === null) {
$options = array();
} elseif (is_string($options)) {
$field = $options;
$options = 0;
}

if (!empty($field)) {
$this->setEntity($field);
}

if (is_array($options) && isset($options[$key])) {
return $options;
}

$entity = $this->entity();
$model = $this->model();
$name = $model === $entity[0] && isset($entity[1]) ? $entity[1] : $entity[0];
$last = $entity[count($entity) - 1];
if (in_array($last, $this->_fieldSuffixes)) {
$name .= '[' . $last . ']';
}

if (is_array($options)) {
$options[$key] = $name;
return $options;
}
return $name;
}
return parent::_name($options, $field, $key);
}

/**
* Generates option lists for common <select /> menus
*
Expand Down
22 changes: 11 additions & 11 deletions tests/TestCase/View/Helper/FormHelperTest.php
Expand Up @@ -6348,7 +6348,7 @@ public function testPostLink() {
$this->assertTags($result, array(
'form' => array(
'method' => 'post', 'action' => '/posts/delete/1',
'name' => 'preg:/post_\w+/', 'id' => 'preg:/post_\w+/', 'style' => 'display:none;'
'name' => 'preg:/post_\w+/', 'style' => 'display:none;'
),
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
'/form',
Expand All @@ -6361,7 +6361,7 @@ public function testPostLink() {
$this->assertTags($result, array(
'form' => array(
'method' => 'post', 'action' => '/posts/delete/1',
'name' => 'preg:/post_\w+/', 'id' => 'preg:/post_\w+/', 'style' => 'display:none;'
'name' => 'preg:/post_\w+/', 'style' => 'display:none;'
),
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'DELETE'),
'/form',
Expand All @@ -6374,7 +6374,7 @@ public function testPostLink() {
$this->assertTags($result, array(
'form' => array(
'method' => 'post', 'action' => '/posts/delete/1',
'name' => 'preg:/post_\w+/', 'id' => 'preg:/post_\w+/', 'style' => 'display:none;'
'name' => 'preg:/post_\w+/', 'style' => 'display:none;'
),
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
'/form',
Expand All @@ -6387,7 +6387,7 @@ public function testPostLink() {
$this->assertTags($result, array(
'form' => array(
'method' => 'post', 'action' => '/posts/delete/1',
'name' => 'preg:/post_\w+/', 'id' => 'preg:/post_\w+/', 'style' => 'display:none;'
'name' => 'preg:/post_\w+/', 'style' => 'display:none;'
),
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
'/form',
Expand All @@ -6403,7 +6403,7 @@ public function testPostLink() {
$this->assertTags($result, array(
'form' => array(
'method' => 'post', 'target' => '_blank', 'action' => '/posts/delete/1',
'name' => 'preg:/post_\w+/', 'id' => 'preg:/post_\w+/', 'style' => 'display:none;'
'name' => 'preg:/post_\w+/', 'style' => 'display:none;'
),
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
'/form',
Expand All @@ -6421,7 +6421,7 @@ public function testPostLink() {
$this->assertTags($result, array(
'form' => array(
'method' => 'post', 'action' => '/items/delete/10',
'name' => 'preg:/post_\w+/', 'id' => 'preg:/post_\w+/', 'style' => 'display:none;'
'name' => 'preg:/post_\w+/', 'style' => 'display:none;'
),
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
'/form',
Expand All @@ -6446,7 +6446,7 @@ public function testPostLinkAfterGetForm() {
$this->assertTags($result, array(
'form' => array(
'method' => 'post', 'action' => '/posts/delete/1',
'name' => 'preg:/post_\w+/', 'id' => 'preg:/post_\w+/', 'style' => 'display:none;'
'name' => 'preg:/post_\w+/', 'style' => 'display:none;'
),
array('input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST')),
array('input' => array('type' => 'hidden', 'name' => '_csrfToken', 'value' => 'testkey')),
Expand Down Expand Up @@ -6478,7 +6478,7 @@ public function testPostLinkFormBuffer() {
$this->assertTags($result, array(
'form' => array(
'method' => 'post', 'action' => '/posts/delete/1',
'name' => 'preg:/post_\w+/', 'id' => 'preg:/post_\w+/', 'style' => 'display:none;'
'name' => 'preg:/post_\w+/', 'style' => 'display:none;'
),
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
'/form'
Expand All @@ -6497,14 +6497,14 @@ public function testPostLinkFormBuffer() {
$this->assertTags($result, array(
'form' => array(
'method' => 'post', 'action' => '/posts/delete/1',
'name' => 'preg:/post_\w+/', 'id' => 'preg:/post_\w+/', 'style' => 'display:none;'
'name' => 'preg:/post_\w+/', 'style' => 'display:none;'
),
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
'/form',
array(
'form' => array(
'method' => 'post', 'action' => '/posts/delete/2',
'name' => 'preg:/post_\w+/', 'id' => 'preg:/post_\w+/', 'style' => 'display:none;'
'name' => 'preg:/post_\w+/', 'style' => 'display:none;'
),
),
array('input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'DELETE')),
Expand All @@ -6522,7 +6522,7 @@ public function testPostLinkFormBuffer() {
$this->assertTags($result, array(
'form' => array(
'method' => 'post', 'action' => '/posts/delete/1',
'name' => 'preg:/post_\w+/', 'id' => 'preg:/post_\w+/', 'style' => 'display:none;'
'name' => 'preg:/post_\w+/', 'style' => 'display:none;'
),
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
'/form'
Expand Down

0 comments on commit a87ef06

Please sign in to comment.