Problem/Motivation

After requesting a translation and reviewing the translation the next step is usually to save the review, but if we try to save the review and the title field is empty we get an error since every node must have a title.

Proposed resolution

Add an error message if you try to save a review that contains an empty title field.

Remaining tasks

create patch, Review and commit.

User interface changes

Data model changes

Original report by [juanse254]

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

juanse254 created an issue. See original summary.

juanse254’s picture

Status: Active » Needs review
Issue tags: +Needs tests
FileSize
867 bytes

This should fix it, tests needed.

Status: Needs review » Needs work

The last submitted patch, 2: Review_job_item_empty-256683-2.patch, failed testing.

The last submitted patch, 2: Review_job_item_empty-256683-2.patch, failed testing.

joshi.rohit100’s picture

+++ b/src/Form/JobItemForm.php
@@ -181,10 +181,13 @@ class JobItemForm extends TmgmtFormBase {
+    if (!$form_state->getValue('title|0|value')['translation']) {
+      $form_state->setErrorByName('title|0|value', 'The title field is empty.');
+    }

t() => $this->t()

juanse254’s picture

Status: Needs work » Needs review
FileSize
748 bytes
975 bytes

This will pass the tests i guess, still working in the tests.

juanse254’s picture

Status: Needs review » Needs work

The last submitted patch, 7: Review_job_item_empty-256683-7-TEST-ONLY.patch, failed testing.

The last submitted patch, 7: Review_job_item_empty-256683-7-TEST-ONLY.patch, failed testing.

juanse254’s picture

Status: Needs work » Needs review
joshi.rohit100’s picture

+++ b/src/Tests/TMGMTUiTest.php
@@ -473,6 +473,27 @@ class TMGMTUiTest extends TMGMTTestBase {
+    // Tests that there is always a title.
+    \Drupal::state()->set('tmgmt.test_source_data', array(
+      'title' => array(
+        '0|value' => array(
+          '#text' => '<p><em><strong>Source text bold and Italic</strong></em></p>',
+          '#label' => 'Title',
+        ),
+      ),
+      'body' => array(
+        'deep_nesting' => array(
+          '#text' => '<p><em><strong>Source body bold and Italic</strong></em></p>',
+          '#label' => 'Body',
+        )
+      ),
+    ));

can we use short array syntax ?

juanse254’s picture

We could but following the way the rest of the test is written, leaving it the way it is would be the best.

miro_dietiker’s picture

Status: Needs review » Needs work

The domain of a job, item and data item is completely decoupled from the node source.
We can not just check for a magic key like "title" and claim it can not be empty because it results in fatal errors.

What we know is that the source contained text and thus a valid translation can not be empty.
Independent of the item name, we should always warn about such a situation and possibly deny it.
(I'm pretty sure there are very special cases where this is not a valid check but let's ignore them until we found them...)

If this is not enough, a source would need to be able to declare that an item is required / can not be empty so TMGMT can check the integrity constraints without doing item key assumption.

And finally, the source need to check the situation when writing things back and reject it. Anyway, as long as TMGMT doesn't know enough about the source constraints, any source might reject what is provided by tmgmt with its validation. Most importantly we should trigger entity validation on the sources.

Some aspects i mentioned above can be followups...

juanse254’s picture

Status: Needs work » Needs review
FileSize
3.07 KB
2.19 KB

This should do it, we need a diferent approach.

joshi.rohit100’s picture

+++ b/src/Form/JobItemForm.php
@@ -170,6 +170,25 @@
+   */
+  private function getParentKey($name, array $parent_array) {
+    foreach ($parent_array as $key => $value) {

Do we use private in D8, I mean I have seen some places in core where we are using private but should we use this here ?

miro_dietiker’s picture

+++ b/src/Form/JobItemForm.php
@@ -181,10 +200,19 @@ class JobItemForm extends TmgmtFormBase {
+    foreach ($form_state->getValues() as $key => $value) {
+      if (is_array($value) && isset($value['translation'])) {
...
+        if (($value['translation'] == '') && ($value['source'] != '') && ($form_state->getTriggeringElement()['#value'] != 'Validate HTML tags')) {

That traversing looks odd, although i see that validateTags does it similarly...
What confuses me is that we should know what data items are part of the screen and we should know through what we iterate. And if not, we should offer an API to avoid this ugly lookup with trial-and-error...
We might need to discuss with Berdir, but i really think TMGMT should provide better helpers here.

edurenye’s picture

Status: Needs review » Reviewed & tested by the community

Private it's fine if we just want that function to be called inside the class.
About @miro_dietiker comment, then maybe we better create a follow up to discuss this and if it's the case add those helpers.
For me this issue seems solved and the code looks good.

Berdir’s picture

Title: Review job item without title » Saving a node translation without title results in an error
Status: Reviewed & tested by the community » Fixed
Issue tags: -Needs tests

Can someone open a follow-to discuss how to improve this?

Messing with the form is ugly, I don't think we can change that. But what we can consider to change is move this to the API, possibly even give the source a chance at validating.

Not all fields are required, it should be fine to leave a non-required field empty for example. The content entity source could then account for that.

miro_dietiker’s picture

Hm, you didn't push. I thus committed and pushed now...
Followups still not created.

miro_dietiker’s picture

Created followup for extended validation:
#2587823: Validate review form through source plugins

Status: Fixed » Closed (fixed)

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