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

manipulateVariablesInPowermailAllMarker for array fields #956

Open
kitzberger opened this issue Jan 19, 2024 · 0 comments · May be fixed by #965
Open

manipulateVariablesInPowermailAllMarker for array fields #956

kitzberger opened this issue Jan 19, 2024 · 0 comments · May be fixed by #965

Comments

@kitzberger
Copy link
Contributor

kitzberger commented Jan 19, 2024

I'm trying to make manipulateVariablesInPowermailAllMarker work to manipulate the values of an array field (e.g. checkbox, multiselect) in the {powermail_all} marker.

Let's assume my field my_checkboxes is defined like this and the user selects option 1 and 3.

Option One|1
Option Two|2
Option Three|3

And now I want to manipulate the selected options via TypoScript:

plugin.tx_powermail.settings.setup {
    manipulateVariablesInPowermailAllMarker {
        optinMail {
            my_checkboxes = TEXT
            my_checkboxes.field = value
        }
    }
}

Unfortunately this seems to have a bug: value is always the json notation of all selected options (e.g. ["1","3"]), i.e. in the mail the value is rendered as ["1","3"], ["1","3"]. Is there another property I oughta use to access the single option's value?

I think the problem roots in how ManipulateValueWithTypoScriptViewHelper.php ignores the correctly passed {subValue} from PowermailAll/Mail.html:

<f:for each="{answer.value}" as="subValue" iteration="index">
	<f:if condition="{subValue}">
		<vh:misc.manipulateValueWithTypoScript answer="{answer}" type="{type}">{subValue}</vh:misc.manipulateValueWithTypoScript><f:if condition="{index.isLast}"><f:else>, </f:else></f:if>
	</f:if>
</f:for>
    public function render(): string
    {
        $answer = $this->arguments['answer'];
        $type = $this->arguments['type'];
        $value = $this->renderChildren(); // this is subValue!
        if ($answer->getField()) {
            if (
                isset($this->typeToTsType[$type]) &&
                !empty($this->typoScriptContext[$this->typeToTsType[$type] . '.'][$answer->getField()->getMarker()])) {
                $this->contentObjectRenderer->start($answer->_getProperties());
                $value = $this->contentObjectRenderer->cObjGetSingle(
                    $this->typoScriptContext[$this->typeToTsType[$type] . '.'][$answer->getField()->getMarker()],
                    $this->typoScriptContext[$this->typeToTsType[$type] . '.'][$answer->getField()->getMarker() . '.']
                );
            }
        }
        return (string)$value;
    }

When changing $this->contentObjectRenderer->start($answer->_getProperties()); to $this->contentObjectRenderer->start(['value' => $value]); it's working fine.

kitzberger added a commit to GFEMediaGmbH/powermail that referenced this issue Feb 9, 2024
Without this patch it's not possible to use manipulateVariablesInPowermailAllMarker
to manipulate values of an array field such as checkboxes and multiselect.

Example:

```
plugin.tx_powermail.settings.setup {
    manipulateVariablesInPowermailAllMarker {
        optinMail {
            my_checkboxes = TEXT
            my_checkboxes.field = value
        }
    }
}
```

Resolves: in2code-de#956
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

Successfully merging a pull request may close this issue.

1 participant