Homepage
Main navigation
Main content
Additional information
October Tricks
Login / Sign up
Quality Guidelines
About
GitHub
Propose new content
October CMS resources and help articles
Simple and to the point. Optimized by the community.
×
Login / Sign up
Quality Guidelines
About
GitHub
Propose new content
Edit trick
Changes will be published after manual review
Title
Give your trick a describing title. Do
not
start with «How to...».
Your trick
Keep it short and concise! Markdown is supported.
**Update March 2019**: [Issue #209](https://github.com/rainlab/translate-plugin/issues/209) that caused this problem has been solved. Starting from October Build 449 you should no longer have to take care of the translations yourself. ============== Due to [issue #209](https://github.com/rainlab/translate-plugin/issues/209) translations in a relation modal are not saved correctly. To fix this problem, do the following: 1. Create the following trait in `plugins/yourvendor/yourplugin/classes/TranslatableRelation.php`. ```php namespace YourVendor\YourPlugin\Classes; use Illuminate\Support\Facades\DB; /** * @see https://github.com/rainlab/translate-plugin/issues/209#issuecomment-362088300 */ trait TranslatableRelation { /** * This is a temporary fix until * https://github.com/rainlab/translate-plugin/issues/209 * is resolved. */ protected function setTranslatableFields() { if ( ! post('RLTranslate')) { return; } $translatableIndexes = []; $translatableAttributes = []; foreach (post('RLTranslate') as $key => $value) { foreach ($this->translatable as $translatableAttribute) { if (isset($translatableAttribute['index'])) { $translatableIndexes[$translatableAttribute[0]] = ''; $translatableAttributes[$translatableAttribute[0]] = ''; } else { $translatableAttributes[$translatableAttribute] = ''; } } $data = collect($value)->intersectByKeys($translatableAttributes); $indexes = collect($value)->intersectByKeys($translatableIndexes); $obj = DB::table('rainlab_translate_attributes') ->where('locale', $key) ->where('model_id', $this->id) ->where('model_type', get_class($this->model)); if ($obj->count() > 0) { $obj->update(['attribute_data' => $data->toJson()]); } else { DB::table('rainlab_translate_attributes') ->insert([ 'locale' => $key, 'model_id' => $this->id, 'model_type' => get_class($this->model), 'attribute_data' => $data->toJson(), ] ); } foreach ($indexes as $item => $value) { $obj = DB::table('rainlab_translate_indexes') ->where('locale', $key) ->where('model_id', $this->id) ->where('model_type', get_class($this->model)) ->where('item', $item); if ($obj->count() > 0) { $obj->update(['value' => $value]); } else { DB::table('rainlab_translate_indexes') ->insert([ 'locale' => $key, 'model_id' => $this->id, 'model_type' => get_class($this->model), 'item' => $item, 'value' => $value, ] ); } } } } public function afterSave() { $this->setTranslatableFields(); } } ``` 2. Use the trait in the model you are editing via the relation (the modal that is loaded in the modal). ```php class RelatedModel extends Model { use YourVendor\YourPlugin\Classes\TranslatableRelation; }
References
Add additional online resources to your trick
×
Name
URL
+ Add reference
Topics
If your trick fits more than one topic select multiple. Select at least one.
Backend
Plugin Development
CMS
Twig
Themes
Deployment
Tags
You can use existing tags or create new ones. Add at least one.
Submit for review
Cancel
We use cookies to measure the performance of this website. Do you want to accept these cookies?
Accept
Decline