Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

json decoding for multi checkbox selection value is missing #76

Open
Mainbird opened this issue Mar 9, 2023 · 0 comments
Open

json decoding for multi checkbox selection value is missing #76

Mainbird opened this issue Mar 9, 2023 · 0 comments

Comments

@Mainbird
Copy link

Mainbird commented Mar 9, 2023

Hi,

we are using TYPO3 11.5.24 and powermail_cond 10.0.0 and I think I have found a bug with multi checkbox value handling.

When using a powermail form with a multi checkbox selection field where one of them should enable an input field by value matching, then powermail_cond hide the input field initially. So this works as attended, but if we select the trigger checkbox, the input field will still be disabled and hidden.

Our checkbox value which should be enable the input field is "Arbeitnehmer/in". We have used the following powermail condition for this use case:

Conditions

Which field is affected (target field)?
inputX

What should happen to the chosen field?
unhide

Conjunction of the rules (if more than only 1)
OR

Rules

Which field starts the condition (start field)?
checkboxY

Operator
contains value

Value
Arbeitnehmer/in

This was working for TYPO3 10, but fails with TYPO3 11 now. For this reason I have checked the following part of the Comparison evaluate method:

case Rule::OPERATOR_CONTAINS_VALUE:
    return $this->operationContains($leftFieldValue, $valueToMatch); 

which will lead to a comparison of something like this:

strpos('["Arbeitnehmer\/in"]', 'Arbeitnehmer/in')

inside the operationContains method which will return false, because the slash will be escaped. To fix this issue the following method:

  public function getFieldValue(Field $field)
  {
      $value = $field->getText();
      if (($value[0] ?? '') === '{') {
          try {
              return json_decode($value, true, 512, JSON_THROW_ON_ERROR);
          } catch (JsonException $exception) {
              // No JSON, no problem.
          }
      }
      return $value;
  }

could be extended to:

  public function getFieldValue(Field $field)
  {
      $value = $field->getText();
      $firstCharacter = $value[0] ?? '';
      
      if ($firstCharacter === '{' || $firstCharacter === '[') {
          try {
              return json_decode($value, true, 512, JSON_THROW_ON_ERROR);
          } catch (JsonException $exception) {
              // No JSON, no problem.
          }
      }
      return $value;
  }

which will lead to a json_decode of a json formatted array string, so a php array will be checked inside operationContains for multi checkbox values instead of a json decoded array string.

What do you think? :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant