Steps to reproduce:
1. install weigth module on drupal
2. generate content for at least two languages
3. first try to reorder english and it's ok
4. second try to reorder spanish for examle and it doesn't work everytime show 0 as weight
5. go back to english and you will see that all weight from spanish has been saved to english

Proposed solution:
Get translation language from view row and use it on save

Comments

vprocessor created an issue. See original summary.

vprocessor’s picture

Patch attached but I am not sure about that it's correct way to get language from views row

vprocessor’s picture

StatusFileSize
new1.24 KB

Patch updated

andypost’s picture

+++ b/src/Plugin/views/field/WeightSelector.php
@@ -95,10 +95,25 @@ class WeightSelector extends FieldPluginBase {
+      $row->_entity->save();

I guess it no go to save entity here + loop

VaanDeFanel’s picture

I confirm that the patch 3 works on Drupal 8.3.3 with module weight version 8.x-3.1-alpha1. I tested with 2 languages with views.

I hope it will be commited to the next release :)

ziomizar’s picture

Status: Needs review » Needs work
+++ b/src/Plugin/views/field/WeightSelector.php
@@ -95,10 +95,25 @@ class WeightSelector extends FieldPluginBase {
+      $editedLangcode = $row->node_field_data_langcode;

This will work just for node entity, it should works for all the entity types.

We need a more stable way to retrieve the language and then use a more easy syntax to implement this, like:

    foreach ($rows as $key => $row) {
      $language = ...
      $entity = $row['entity'];
      $translation = $entity->getTranslation($language);
      $translation->set($field_name, $row['weight']);
      $translation->save();
    }
fall_0ut’s picture

Status: Needs work » Needs review
StatusFileSize
new1.26 KB

  • ziomizar committed e122414 on 8.x-3.x authored by fall_0ut
    Issue #2892188 by vprocessor, fall_0ut: No multi language support
    
ziomizar’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

Thanks @fall_0ut,

Now just the testing are missing

ziomizar’s picture

Status: Needs work » Fixed
Issue tags: -Needs tests
ReBa’s picture

Status: Fixed » Needs review
StatusFileSize
new688 bytes

I have another problem with multilingual weight.

Reproduction:

  1. Create translatable content type
  2. Create content in multiple languages
  3. Add weight field to the content type
  4. Set weight field non translatable
  5. Create view for weight management
  6. Administer the content you've created

Where I get the error:

The website encountered an unexpected error. Please try again later.</br></br><em class="placeholder">InvalidArgumentException</em>: Invalid translation language () specified. in <em class="placeholder">Drupal\Core\Entity\ContentEntityBase-&gt;getTranslation()</em> (line <em class="placeholder">872</em> of <em class="placeholder">core/lib/Drupal/Core/Entity/ContentEntityBase.php</em>). <pre class="backtrace">Drupal\weight\Plugin\views\field\WeightSelector-&gt;viewsFormSubmit(Array, Object) (Line: 132)
Drupal\views\Form\ViewsFormMainForm-&gt;submitForm(Array, Object) (Line: 187)
Drupal\views\Form\ViewsForm-&gt;submitForm(Array, Object)
call_user_func_array(Array, Array) (Line: 111)
Drupal\Core\Form\FormSubmitter-&gt;executeSubmitHandlers(Array, Object) (Line: 51)
Drupal\Core\Form\FormSubmitter-&gt;doSubmitForm(Array, Object) (Line: 589)
Drupal\Core\Form\FormBuilder-&gt;processForm(&#039;views_form_order_references&#039;, Array, Object) (Line: 318)
Drupal\Core\Form\FormBuilder-&gt;buildForm(&#039;views_form_order_references&#039;, Object) (Line: 216)
Drupal\Core\Form\FormBuilder-&gt;getForm(Object, Object, Array) (Line: 2206)
Drupal\views\Plugin\views\display\DisplayPluginBase-&gt;elementPreRender(Array)
call_user_func(Array, Array) (Line: 378)
Drupal\Core\Render\Renderer-&gt;doRender(Array) (Line: 450)
Drupal\Core\Render\Renderer-&gt;doRender(Array, ) (Line: 195)
Drupal\Core\Render\Renderer-&gt;render(Array, ) (Line: 226)
Drupal\Core\Render\MainContent\HtmlRenderer-&gt;Drupal\Core\Render\MainContent\{closure}() (Line: 582)
Drupal\Core\Render\Renderer-&gt;executeInRenderContext(Object, Object) (Line: 227)
Drupal\Core\Render\MainContent\HtmlRenderer-&gt;prepare(Array, Object, Object) (Line: 117)
Drupal\Core\Render\MainContent\HtmlRenderer-&gt;renderResponse(Array, Object, Object) (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber-&gt;onViewRenderArray(Object, &#039;kernel.view&#039;, Object)
call_user_func(Array, Object, &#039;kernel.view&#039;, Object) (Line: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher-&gt;dispatch(&#039;kernel.view&#039;, Object) (Line: 156)
Symfony\Component\HttpKernel\HttpKernel-&gt;handleRaw(Object, 1) (Line: 68)
Symfony\Component\HttpKernel\HttpKernel-&gt;handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session-&gt;handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle-&gt;handle(Object, 1, 1) (Line: 99)
Drupal\page_cache\StackMiddleware\PageCache-&gt;pass(Object, 1, 1) (Line: 78)
Drupal\page_cache\StackMiddleware\PageCache-&gt;handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware-&gt;handle(Object, 1, 1) (Line: 52)
Drupal\Core\StackMiddleware\NegotiationMiddleware-&gt;handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel-&gt;handle(Object, 1, 1) (Line: 669)
Drupal\Core\DrupalKernel-&gt;handle(Object) (Line: 19)
</pre>

This is probably because the weight field has been added later.
To avoid this problem, I've added a patch which solves the issue whereafter the normal functionality provided is executed properly.

I created a patch working from the current dev branch (today) so the patch applied in #7 should be ignored as it's already merged into the dev branch.

andypost’s picture

Status: Needs review » Reviewed & tested by the community

Nice catch

The last submitted patch, 3: weigth-add-languages-support-2892188-3.patch, failed testing. View results

ziomizar’s picture

@ReBa following your steps I dont get any errors managing the view.

I can reproduce your error with these:

  1. Create translatable content type
  2. Create content in multiple languages
  3. Add weight field to the content type
  4. Set weight field translatable
  5. Add some content
  6. Set the weight field not translatable
  7. Create view for weight management
  8. Administer the content you've created

In any case your patch make sense, thx!

  • ziomizar committed 912d9c7 on 8.x-3.x authored by ReBa
    Issue #2892188 by vprocessor, fall_0ut, ReBa, ziomizar: No multi...
ziomizar’s picture

Status: Reviewed & tested by the community » Fixed
ziomizar’s picture

Status: Fixed » Needs review
StatusFileSize
new634 bytes

I found another bug just for coincidence:

  1. create content typeA
  2. add field field_weight1
  3. create content typeB
  4. add field field_weight2
  5. create content for both content types
  6. create a view test_weight_translation
  7. add field_weight1
  8. add field_weight2
  9. save the view
  10. now after move somenodes and save this error appear
The website encountered an unexpected error. Please try again later.</br></br><em class="placeholder">InvalidArgumentException</em>: Field field_weight2 is unknown. in <em class="placeholder">Drupal\Core\Entity\ContentEntityBase-&gt;getTranslatedField()</em> (line <em class="placeholder">586</em> of <em class="placeholder">core/lib/Drupal/Core/Entity/ContentEntityBase.php</em>). <pre class="backtrace">Drupal\Core\Entity\ContentEntityBase-&gt;get(&#039;field_weight&#039;) (Line: 627)
ziomizar’s picture

StatusFileSize
new584 bytes

removing debugging

ziomizar’s picture

  • ziomizar committed c1a781c on 8.x-3.x
    Issue #2892188 by ziomizar, vprocessor, fall_0ut, ReBa: No multi...
ziomizar’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.