mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
parent
a4e3790196
commit
b5f918765e
2 changed files with 21 additions and 1 deletions
|
@ -368,7 +368,10 @@ class TranslateBehavior extends ModelBehavior {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bind translation for fields, optionally with hasMany association for
|
* Bind translation for fields, optionally with hasMany association for
|
||||||
* fake field
|
* fake field.
|
||||||
|
*
|
||||||
|
* *Note* You should avoid binding translations that overlap existing model properties.
|
||||||
|
* This can cause un-expected and un-desirable behavior.
|
||||||
*
|
*
|
||||||
* @param Model $model instance of model
|
* @param Model $model instance of model
|
||||||
* @param string|array $fields string with field or array(field1, field2=>AssocName, field3)
|
* @param string|array $fields string with field or array(field1, field2=>AssocName, field3)
|
||||||
|
@ -391,6 +394,11 @@ class TranslateBehavior extends ModelBehavior {
|
||||||
$field = $key;
|
$field = $key;
|
||||||
$association = $value;
|
$association = $value;
|
||||||
}
|
}
|
||||||
|
if ($field === 'name') {
|
||||||
|
throw new CakeException(
|
||||||
|
__d('cake_dev', 'You cannot bind a translation named "name".')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (array_key_exists($field, $this->settings[$model->alias])) {
|
if (array_key_exists($field, $this->settings[$model->alias])) {
|
||||||
unset($this->settings[$model->alias][$field]);
|
unset($this->settings[$model->alias][$field]);
|
||||||
|
|
|
@ -868,4 +868,16 @@ class TranslateBehaviorTest extends CakeTestCase {
|
||||||
|
|
||||||
$this->assertFalse($result);
|
$this->assertFalse($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test that an exception is raised when you try to over-write the name attribute.
|
||||||
|
*
|
||||||
|
* @expectedException CakeException
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testExceptionOnNameTranslation() {
|
||||||
|
$this->loadFixtures('Translate', 'TranslatedItem');
|
||||||
|
$TestModel = new TranslatedItem();
|
||||||
|
$TestModel->bindTranslation(array('name' => 'name'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue