Problem/Motivation

When requesting a translation/creating a new job the label is supposed to be available for the user so its easy identify the job. When we pick a diferent target language in the dropdown box the label field hides and then we cannot change the value of the label anymore.

Steps to Recreate:

1.- Request a translation for a translatable node.
2.- Pick a different target language than the default in the dropdown list.

Proposed resolution

Make the label field available all the time and only set the default value if after a change the in the form the field remains empty.

Remaining tasks

User interface changes

After Change
Before Change

Data model changes

Original report by [username]

Comments

juanse254 created an issue. See original summary.

joshi.rohit100’s picture

Status: Active » Needs review
StatusFileSize
new819 bytes
juanse254’s picture

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

lets add some tests here.

joshi.rohit100’s picture

Assigned: Unassigned » joshi.rohit100
joshi.rohit100’s picture

Status: Needs work » Needs review
StatusFileSize
new619 bytes

Here is the test only patch.

Status: Needs review » Needs work

The last submitted patch, 5: 2550597-test-only-patch-5.patch, failed testing.

juanse254’s picture

Great, now please post both test and fix in a single patch please.

joshi.rohit100’s picture

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

contains test with fix. (contains minor change in test case). I will upload the new test only patch.

joshi.rohit100’s picture

StatusFileSize
new623 bytes

Here is test only patch and now should fail properly :)

juanse254’s picture

Lets wait for the tests, for further reference please always upload an interdiff of the changes so its easy to see the changes in code between patches. Have a look at this.

The last submitted patch, 8: 2550597-8.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 9: 2550597-9-test-only.patch, failed testing.

joshi.rohit100’s picture

Status: Needs work » Needs review
StatusFileSize
new1.41 KB
new640 bytes

Now as #9 is failing properly, here is patch with fix and test case.

This interdiff is from #8.

edurenye’s picture

Status: Needs review » Needs work

This test is wrong, you don't change the language, to assert that you should use ajax to change to french.

edurenye’s picture

And when you modify somthing, please, ulpoad the test_only, the patch and the interdiff in this order and in the same comment. Thanks.

joshi.rohit100’s picture

@edurenye : thanks for your feedback but I think, ajax trigger on language is already there in 'testCheckoutForm'

$job = tmgmt_job_create('en', 'de', 0);
    $job->save();
    $edit = array(
      'target_language' => 'de',
    );
    $this->drupalPostAjaxForm('admin/tmgmt/jobs/' . $job->id(), $edit, 'target_language');
    $this->assertFieldByXPath('//select[@id="edit-translator"]/option[1]', 'Test translator (auto created)');

What I have just check is that label field is available after ajax or not.

The last submitted patch, 13: 2550597-13.patch, failed testing.

edurenye’s picture

Yes, but is checking "de" language that is the first in the list, so the form is the default one, so this method is not called, maybe we should change to the second that is greek.
Maybe somthing like this:

$edit = array(
      'target_language' => 'el',
      'settings[action]' => 'translate',
    );
    $this->drupalPostAjaxForm('admin/tmgmt/jobs/' . $job->id(), $edit, 'target_language');
    $this->assertFieldByXPath('//label[@for="edit-label-0-value"]', 'Label');

I'm not really sure that the method is not called, but if you try it manually, the id change when the method is called, so I deducted this.

Maybe other solution could be just deleting those lines, I don't understand why we replace the label when changing the language, if we delete that, the default label is set properly in the job. So I don't know why we need that.

juanse254’s picture

As suggested by edurenye, changing the default language in the ajax form, from de to any other will make the label field to disappear. Please do so in order to test, also about deleting the lines, they were added by berdir in the first place so maybe he can enlighten us on this.

joshi.rohit100’s picture

Status: Needs work » Needs review
StatusFileSize
new1.61 KB
new830 bytes
new831 bytes
joshi.rohit100’s picture

The last submitted patch, 20: 2550597-20.patch, failed testing.

juanse254’s picture

rebase please.

EDIT: i think we can drop the whole part from the todo and down, just add a test that fails without the fix and covers the issue and the patch(test + issue fix) which passes.

joshi.rohit100’s picture

Status: Needs review » Needs work

I don't know why the test only case is passing and test+fix is failing ahhhhhh....

edurenye’s picture

Don't desperate :)
There were something commited between both, just rebase and upload.
I think maybe we don't need 'settings[action]' => 'translate', I just adapted another assertion there. What I don't understand is why the test_only is not failing, seems like the problem is just present when you check it manually, and I don't get to know why.

+++ b/src/Form/JobForm.php
@@ -543,8 +543,8 @@ class JobForm extends TmgmtFormBase {
     // Replace value of the label field with ajax on language change.
     // @todo This manual overwrite is necessary because somehow an old job entity seems to be used.
-    $form['info']['label']['#value'] = $form_state->getValue('label');
-    $response->addCommand(new ReplaceCommand('#tmgmt-ui-label', $this->renderer->render($form['info']['label'])));
+    $form['label']['widget'][0]['value']['#value'] = $form_state->getValue('label')[0]['value'];
+    $response->addCommand(new ReplaceCommand('#tmgmt-ui-label', $this->renderer->render($form['label']['widget'][0]['value'])));

And I think the solution may be just delete this. Because is old code that is not so understandable, so check what whappens if we delete that. If somthing breaks, then will help us to understand what is doing this.

edurenye’s picture

@joshi.rohit100 are you still working in this issue?

joshi.rohit100’s picture

Status: Needs work » Needs review
StatusFileSize
new909 bytes

@edurenye: Sorry for delaying. Yes I am still on it.

And as per #25, lets see what happens.

juanse254’s picture

Status: Needs review » Needs work

Once again, we need test coverage for this.

joshi.rohit100’s picture

I am still facing same problem as test-only patch is not failing. Don't know why. Cache ?

joshi.rohit100’s picture

Status: Needs work » Needs review
StatusFileSize
new777 bytes
new1.65 KB

It didn't work locally but I am uploading it here for feedback.

edurenye’s picture

Status: Needs review » Needs work

Thanks for your answer.
Seems to work without those lines, so now we need the difficult part, so make a test that fails with the lines and works without the lines.
I tried to dissable the cache and the test is still don't working properly.
@juanse254 found the problem, it just happens if tmgmt_file is enabled, but then all the test breaks...

LKS90’s picture

+++ b/src/Tests/TMGMTUiTest.php
@@ -249,6 +249,13 @@ class TMGMTUiTest extends TMGMTTestBase {
+    // Check for label field.
...
+      'target_language' => 'el',
...
+		$this->drupalPostAjaxForm('admin/tmgmt/jobs/' . $job->id(), $edit, 'target_language');
+		$this->assertField('label[0][value]', 'Label');

Please set up your IDE to use two spaces as a tab (as listed in the coding guidelines).

edurenye’s picture

Status: Needs work » Reviewed & tested by the community

Ok, @Berdir says that this can just be tested manually, so I tested it manually and works fine.
The good patch is the 27: https://www.drupal.org/node/2550597#comment-10232361

berdir’s picture

Status: Reviewed & tested by the community » Needs work

That is correct, but the feedback from @LKS90 hasn't been addressed.

joshi.rohit100’s picture

Status: Needs work » Needs review
StatusFileSize
new1.65 KB
new748 bytes

Diff is from #30

juanse254’s picture

i think that the only patch we need due the case is 27. We are not adding any test for this, thats why even though LKS90 is right makes no sense to do those changes since the test is not going to be part of the patch.

joshi.rohit100’s picture

StatusFileSize
new909 bytes

OK!

So in this, I have removed test case.

edurenye’s picture

Status: Needs review » Reviewed & tested by the community

Ok, it's the same as 27, so is the one that works.
Good job!

berdir’s picture

Status: Reviewed & tested by the community » Fixed
Issue tags: -Needs tests

Confirmed manually, nice find.

Status: Fixed » Closed (fixed)

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