mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Continuing work on Helper::setEntity and associated methods
This commit is contained in:
parent
2941e89da3
commit
50ec80ff50
6 changed files with 77 additions and 16 deletions
0
app/tmp/cache/models/empty
vendored
Executable file
0
app/tmp/cache/models/empty
vendored
Executable file
0
app/tmp/cache/persistent/empty
vendored
Executable file
0
app/tmp/cache/persistent/empty
vendored
Executable file
0
app/tmp/cache/views/empty
vendored
Executable file
0
app/tmp/cache/views/empty
vendored
Executable file
|
@ -362,7 +362,7 @@ class Helper extends Overloadable {
|
|||
|
||||
if ($setScope) {
|
||||
$view->modelScope = false;
|
||||
} elseif (join('.', $view->entity()) == $entity) {
|
||||
} elseif (!empty($view->entityPath) && $view->entityPath == $entity) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -371,9 +371,11 @@ class Helper extends Overloadable {
|
|||
$view->association = null;
|
||||
$view->modelId = null;
|
||||
$view->modelScope = false;
|
||||
$view->entityPath = null;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
$view->entityPath = $entity;
|
||||
$model = $view->model;
|
||||
$sameScope = $hasField = false;
|
||||
$parts = array_values(Set::filter(explode('.', $entity), true));
|
||||
|
@ -538,14 +540,24 @@ class Helper extends Overloadable {
|
|||
* @return boolean True on errors.
|
||||
*/
|
||||
function tagIsInvalid($model = null, $field = null, $modelID = null) {
|
||||
$view =& ClassRegistry::getObject('view');
|
||||
foreach (array('model', 'field', 'modelID') as $key) {
|
||||
if (empty(${$key})) {
|
||||
${$key} = $this->{$key}();
|
||||
}
|
||||
}
|
||||
$view =& ClassRegistry::getObject('view');
|
||||
|
||||
$errors = $this->validationErrors;
|
||||
|
||||
|
||||
if (!empty($view->entityPath)) {
|
||||
$check = $view->entityPath;
|
||||
$path = explode('.',$check);
|
||||
if (count($path) == 1 || is_numeric($path[0])) {
|
||||
$check = $model . '.' . $check;
|
||||
}
|
||||
return Set::extract($errors,$check);
|
||||
}
|
||||
|
||||
if ($view->model !== $model && isset($errors[$view->model][$model])) {
|
||||
$errors = $errors[$view->model];
|
||||
}
|
||||
|
@ -594,7 +606,6 @@ class Helper extends Overloadable {
|
|||
*/
|
||||
function __name($options = array(), $field = null, $key = 'name') {
|
||||
$view =& ClassRegistry::getObject('view');
|
||||
|
||||
if ($options === null) {
|
||||
$options = array();
|
||||
} elseif (is_string($options)) {
|
||||
|
@ -615,7 +626,18 @@ class Helper extends Overloadable {
|
|||
$name = $field;
|
||||
break;
|
||||
default:
|
||||
$name = 'data[' . join('][', $view->entity()) . ']';
|
||||
$entity = $view->entity();
|
||||
if (!empty($view->entityPath)) {
|
||||
$check = $view->entityPath;
|
||||
$path = explode('.',$check);
|
||||
$model = $this->model();
|
||||
if ((count($path) == 1 && $model != $this->field()) || is_numeric($path[0])) {
|
||||
debug($model); debug($this->field());
|
||||
array_unshift($path,$model);
|
||||
}
|
||||
$entity = $path;
|
||||
}
|
||||
$name = 'data[' . join('][', $path) . ']';
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -643,25 +665,35 @@ class Helper extends Overloadable {
|
|||
$options = 0;
|
||||
}
|
||||
|
||||
if (!empty($field)) {
|
||||
$this->setEntity($field);
|
||||
}
|
||||
|
||||
if (is_array($options) && isset($options[$key])) {
|
||||
return $options;
|
||||
}
|
||||
|
||||
|
||||
if (!empty($field)) {
|
||||
$this->setEntity($field);
|
||||
}
|
||||
|
||||
$view =& ClassRegistry::getObject('view');
|
||||
$result = null;
|
||||
|
||||
|
||||
$modelName = $this->model();
|
||||
$fieldName = $this->field();
|
||||
$modelID = $this->modelID();
|
||||
|
||||
if (!empty($this->data) && !empty($view->entityPath)) {
|
||||
$check = $view->entityPath;
|
||||
$path = explode('.',$check);
|
||||
if ((count($path) == 1 && $this->model() != $this->field()) || is_numeric($path[0])) {
|
||||
$field = $this->model() . '.' . $check;
|
||||
}
|
||||
$result = Set::extract($this->data,$check);
|
||||
}
|
||||
|
||||
if (is_null($fieldName)) {
|
||||
$fieldName = $modelName;
|
||||
$modelName = null;
|
||||
}
|
||||
|
||||
|
||||
if (isset($this->data[$fieldName]) && $modelName === null) {
|
||||
$result = $this->data[$fieldName];
|
||||
} elseif (isset($this->data[$modelName][$fieldName])) {
|
||||
|
@ -676,7 +708,6 @@ class Helper extends Overloadable {
|
|||
}
|
||||
|
||||
if (is_array($result)) {
|
||||
$view =& ClassRegistry::getObject('view');
|
||||
if (array_key_exists($view->fieldSuffix, $result)) {
|
||||
$result = $result[$view->fieldSuffix];
|
||||
}
|
||||
|
|
|
@ -629,6 +629,22 @@ class HelperTest extends CakeTestCase {
|
|||
$this->assertEqual($this->View->field,'created');
|
||||
$this->assertEqual($this->View->modelId,1);
|
||||
$this->assertEqual($this->View->fieldSuffix,'year');
|
||||
|
||||
$this->Helper->data['HelperTestPost'][2]['HelperTestComment'][1]['title'] = 'My Title';
|
||||
$result = $this->Helper->value('HelperTestPost.2.HelperTestComment.1.title');
|
||||
$this->assertEqual($result,'My Title');
|
||||
|
||||
$this->Helper->data['HelperTestPost'][2]['HelperTestComment'][1]['created']['year'] = 2008;
|
||||
$result = $this->Helper->value('HelperTestPost.2.HelperTestComment.1.created.year');
|
||||
$this->assertEqual($result,2008);
|
||||
|
||||
$this->Helper->data[2]['HelperTestComment'][1]['created']['year'] = 2008;
|
||||
$result = $this->Helper->value('HelperTestPost.2.HelperTestComment.1.created.year');
|
||||
$this->assertEqual($result,2008);
|
||||
|
||||
$this->Helper->data['HelperTestPost']['title'] = 'My Title';
|
||||
$result = $this->Helper->value('title');
|
||||
$this->assertEqual($result,'My Title');
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1477,7 +1477,7 @@ class FormHelperTest extends CakeTestCase {
|
|||
'label' => array('for'),
|
||||
'preg:/[^<]+/',
|
||||
'/label',
|
||||
'input' => array('type' => 'text', 'name', 'value' => '', 'id', 'class' => 'form-error'),
|
||||
'input' => array('type' => 'text', 'name', 'value' => '', 'id'),
|
||||
'/div'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
@ -1602,7 +1602,7 @@ class FormHelperTest extends CakeTestCase {
|
|||
'/option',
|
||||
'/select',
|
||||
'/div'
|
||||
);
|
||||
); debug($result,true);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$result = $this->Form->input('email', array(
|
||||
|
@ -5475,5 +5475,19 @@ class FormHelperTest extends CakeTestCase {
|
|||
);
|
||||
$this->assertTags($result, $expected);
|
||||
}
|
||||
|
||||
function testMultiRecordForm() {
|
||||
$this->Form->create('ValidateProfile');
|
||||
$this->Form->validationErrors['ValidateProfile'][2]['ValidateItem'][1]['name'] = 'Error in field name';
|
||||
$result = $this->Form->error('ValidateProfile.2.ValidateItem.1.name');
|
||||
$this->assertTags($result, array('div' => array('class' => 'error-message'), 'Error in field name', '/div'));
|
||||
|
||||
$this->Form->validationErrors['ValidateProfile'][2]['city'] = 'Error in field city';
|
||||
$result = $this->Form->error('ValidateProfile.2.city');
|
||||
$this->assertTags($result, array('div' => array('class' => 'error-message'), 'Error in field city', '/div'));
|
||||
|
||||
$result = $this->Form->error('2.city');
|
||||
$this->assertTags($result, array('div' => array('class' => 'error-message'), 'Error in field city', '/div'));
|
||||
}
|
||||
}
|
||||
?>
|
Loading…
Reference in a new issue