mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 02:56:15 +00:00
Fixing ClassRegistry that was incorrectly checking class inheritance
Fixing Model class that was incorrectly sending model names to be instantiated Fixing more FormHelper tests
This commit is contained in:
parent
1941be6a76
commit
ef5650c034
4 changed files with 19 additions and 15 deletions
|
@ -702,10 +702,13 @@ class Model extends Object {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isset($this->{$assoc}) || $this->{$assoc}->name !== $className) {
|
if (!isset($this->{$assoc}) || $this->{$assoc}->name !== $className) {
|
||||||
$model = array('class' => $plugin . '.' . $className, 'alias' => $assoc);
|
if ($plugin) {
|
||||||
|
$plugin .= '.';
|
||||||
|
}
|
||||||
|
$model = array('class' => $plugin . $className, 'alias' => $assoc);
|
||||||
$this->{$assoc} = ClassRegistry::init($model);
|
$this->{$assoc} = ClassRegistry::init($model);
|
||||||
if ($plugin) {
|
if ($plugin) {
|
||||||
ClassRegistry::addObject($plugin . '.' . $className, $this->{$assoc});
|
ClassRegistry::addObject($plugin . $className, $this->{$assoc});
|
||||||
}
|
}
|
||||||
if ($assoc) {
|
if ($assoc) {
|
||||||
$this->tableToModel[$this->{$assoc}->table] = $assoc;
|
$this->tableToModel[$this->{$assoc}->table] = $assoc;
|
||||||
|
|
|
@ -1882,7 +1882,7 @@ class FormHelperTest extends CakeTestCase {
|
||||||
'label' => array('for' => 'ObjectField'),
|
'label' => array('for' => 'ObjectField'),
|
||||||
'Field',
|
'Field',
|
||||||
'/label',
|
'/label',
|
||||||
'input' => array('type' => 'text', 'name' => 'data[Object][field]', 'id' => 'ObjectField'),
|
'input' => array('type' => 'text', 'name' => 'data[Object][field]', 'id' => 'ModelField'),
|
||||||
'A message to you, Rudy',
|
'A message to you, Rudy',
|
||||||
'/div'
|
'/div'
|
||||||
);
|
);
|
||||||
|
|
|
@ -135,16 +135,18 @@ class ClassRegistry {
|
||||||
App::uses($plugin . 'AppModel', $pluginPath . 'Model');
|
App::uses($plugin . 'AppModel', $pluginPath . 'Model');
|
||||||
App::uses($class, $pluginPath . 'Model');
|
App::uses($class, $pluginPath . 'Model');
|
||||||
|
|
||||||
if (class_exists($class) && $class instanceof Model) {
|
if (class_exists($class)) {
|
||||||
${$class} = new $class($settings);
|
${$class} = new $class($settings);
|
||||||
} else {
|
$$class = ($$class instanceof Mdoel) ? $$class : null;
|
||||||
if ($strict) {
|
}
|
||||||
|
if (!isset($$class) && $strict) {
|
||||||
return false;
|
return false;
|
||||||
} elseif ($plugin && class_exists($plugin . 'AppModel')) {
|
} elseif ($plugin && class_exists($plugin . 'AppModel')) {
|
||||||
$appModel = $plugin . 'AppModel';
|
$appModel = $plugin . 'AppModel';
|
||||||
} else {
|
} else {
|
||||||
$appModel = 'AppModel';
|
$appModel = 'AppModel';
|
||||||
}
|
}
|
||||||
|
if (!empty($appModel)) {
|
||||||
$settings['name'] = $class;
|
$settings['name'] = $class;
|
||||||
${$class} = new $appModel($settings);
|
${$class} = new $appModel($settings);
|
||||||
}
|
}
|
||||||
|
|
|
@ -156,11 +156,10 @@ class FormHelper extends AppHelper {
|
||||||
return $this->fieldset[$model]['key'];
|
return $this->fieldset[$model]['key'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($key === 'fields') {
|
||||||
if (!isset($this->fieldset[$model]['fields'])) {
|
if (!isset($this->fieldset[$model]['fields'])) {
|
||||||
$fields = $this->fieldset[$model]['fields'] = $object->schema();
|
$fields = $this->fieldset[$model]['fields'] = $object->schema();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($key === 'fields') {
|
|
||||||
if (empty($field)) {
|
if (empty($field)) {
|
||||||
foreach ($object->hasAndBelongsToMany as $alias => $assocData) {
|
foreach ($object->hasAndBelongsToMany as $alias => $assocData) {
|
||||||
$this->fieldset[$object->alias]['fields'][$alias] = array('type' => 'multiple');
|
$this->fieldset[$object->alias]['fields'][$alias] = array('type' => 'multiple');
|
||||||
|
|
Loading…
Add table
Reference in a new issue