milesj / utility

[Deprecated] A CakePHP plugin for common utility classes.
MIT License
69 stars 24 forks source link

Handle fields using TranslateBehavior and being edited in multiple locales at once #28

Closed redd closed 9 years ago

redd commented 10 years ago

Pull request for issue #27 with proper formatting.

milesj commented 10 years ago

I'm pretty sure your changes to _makeUnique() is fetching all records, since $where is never modified.

redd commented 10 years ago

Yes that's right, this is because you can't simply put $model['slugfield'] => $translated_slug in conditions (and _makeUnique() recives translated slug as a param).

milesj commented 10 years ago

Shouldn't you be doing a wildcard search for the original slug, then looping through all the results that have that slug and do the comparison checks?

redd commented 10 years ago

You are right, but any idea how to retrive original slug having translation?

milesj commented 10 years ago

I've never used the TranslateBehavior before, so what does it do to find() exactly?

redd commented 10 years ago

It join's I18n table, but this is a bit complicated: http://api.cakephp.org/2.4/source-class-TranslateBehavior.html#96-188

Also after reciving original and translated content it replaces fields with translated ones: http://api.cakephp.org/2.4/source-class-TranslateBehavior.html#280-325

redd commented 10 years ago

One more thing I've just remembered - you can't simply discover original slug (not translated) from model's table, because TranslateBehavior saves sometimes in model's table translated content (it depends on $model->locale while saving).

In model's table you can have content in many languages (while retriving it's overwritten by data from i18n table). So there is really no default/original value of data.

milesj commented 10 years ago

Hrmm, I'm going to have to setup a test locally to see how this works. Will get back to you on this.