Problem/Motivation

When I review a translation and want to validate the HTML tags, I get an exception about preg_match_all() expecting a string as the second argument. In some cases it gets an array where the string is hidden inside the key value.

Proposed resolution

If the variable is not a string, try and extract the string from the array and pass it to preg_match_all() as before.

Remaining tasks

Review patch, commit.

User interface changes

None

API changes

None

Data model changes

None

Comments

miro_dietiker’s picture

Status: Needs review » Needs work
+++ b/src/Form/JobItemForm.php
@@ -486,6 +486,12 @@ class JobItemForm extends TmgmtFormBase {
+      !isset($source['value']) ?: $source = $source['value'];
...
+      !isset($translation['value']) ?: $translation = $translation['value'];

Nooooo... A ternary operator is not intended as a replacement for a regular if condition.

It should be only used for a lvalue assignment.
a = b ? c : d;

In all other cases, please write ifs such as:

+    if (!is_string($source) && isset($source['value'])) {
+      $source = $source['value'];
+    };
+    if (!is_string($translation) && isset($translation['value'])) {
+      $translation = $translation['value'];
+    }

But i think we should even check for is_array instead of !is_string.

LKS90’s picture

StatusFileSize
new668 bytes
new859 bytes

Switched to an if statement, got it now.
Also using is_array instead of !is_string now.

LKS90’s picture

Status: Needs work » Needs review
miro_dietiker’s picture

Wow, so much readable! ;-)

berdir’s picture

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

Not going to happen without test coverage that shows how it is wrong and that it is now better :)

LKS90’s picture

Status: Needs work » Closed (cannot reproduce)

Can't reproduce anymore, tried with several translators. Seems like the problem resolved itself in the meantime.