CoreCommunity ExtensionsIncubatorDistributionsTYPO3 4.5 ProjectsTYPO3 4.6 ProjectsTYPO3 4.7 ProjectsTYPO3 6.0 ProjectsTYPO3 6.1 ProjectsTYPO3 6.2 Projects (+)

Bug #38402

###ISSET_fieldname### doesn't work with checkboxes / arrays

Added by Simon Apold 11 months ago. Updated 10 months ago.

Status:Resolved Start date:2012-06-26
Priority:Should have Due date:
Assignee:Reinhard Führicht % Done:

100%

Category:View
Target version:v1.4
Votes: 0

Description

I've got the following checkboxes:

<input type="checkbox" id="topic1" name="contact[topics][]" value="topic1"/><label for="topic1">Topic 1</label>
<input type="checkbox" id="topic2" name="contact[topics][]" value="topic2"/><label for="topic2">Topic 2</label>
<input type="checkbox" id="topic3" name="contact[topics][]" value="topic3"/><label for="topic3">Topic 3</label>

In my Mail-Template i've got a subpart, which should only be displayed, if at least one topic-checkbox ist checked.

<!-- ###ISSET_topics### -->
###LLL:topics###: ###value_topics###
<!-- ###ISSET_topics### -->

This subpart will never be shown.
I think the handleIssetSubpartCondition-method in the Tx_Formhandler_View_Form-Class doesn't handle array-values properly.
It calls tslib_cObj->getGlobal to retrieve the fields value, which will never return an array because of the "is_scalar"-Check.

Tx_Formhandler_View_Form

protected function handleIssetSubpartCondition($condition) {
    $fieldname = $condition;
    $negate = FALSE;
    if(substr($condition, 0, 1) === '!') {
        $fieldname = substr($condition, 1);
        $negate = TRUE;
    }
    $value = $this->globals->getCObj()->getGlobal($fieldname, $this->gp);
    if(is_array($value)) {
        $result = (empty($value));
    }

...

t3lib_cObj->getGlobal

function getGlobal($keyString, $source = NULL) {
    $keys = explode('|', $keyString);
    $numberOfLevels = count($keys);
    $rootKey = trim($keys[0]);
    $value = isset($source) ? $source[$rootKey] : $GLOBALS[$rootKey];

    ...

    if (!is_scalar($value)) {
        $value = '';
    }
    return $value;
}

patch.diff (810 Bytes) Simon Apold, 2012-06-29 08:33

38402.patch (6 kB) Reinhard Führicht, 2012-07-25 16:46

patch_empty_logic.diff (481 Bytes) Christoph Wagner, 2012-08-08 17:03


Related issues

related to Formhandler - Bug #34151: Subpart ###ISSET_fieldname||fieldname### does not work Resolved 2012-02-21
related to Formhandler - Bug #35418: ISSET-check fails on arrays Resolved 2012-03-30

Associated revisions

Revision 64846
Added by Reinhard Führicht 10 months ago

Make conditional subparts like ISSET and IF work with array values (fixes #38402)

Revision 64846
Added by Reinhard Führicht 10 months ago

Make conditional subparts like ISSET and IF work with array values (fixes #38402)

History

Updated by Simon Apold 11 months ago

Another point:

shouldn't it be:

if(is_array($value)) {
   $result = !(empty($value));
}

I think the isset-Handler should return false, if the array is empty an true if not.

Updated by Simon Apold 11 months ago

I attached a patch-file which solves this problem.

Updated by Reinhard Führicht 11 months ago

  • Status changed from New to Accepted
  • Assignee set to Reinhard Führicht
  • Target version set to v1.4

Your patch seems to work only for arrays with a depth of 1.
The cool thing about getGlobal() is that you can use things like this: arrayField|sub|sub|sub|endpoint

What about copying the method getGlobal from tslib_content and just removing the is_scalar() check?

Updated by Reinhard Führicht 10 months ago

I copied "getGlobal" from the core and removed the "is_scalar" line.

Updated by Reinhard Führicht 10 months ago

  • Status changed from Accepted to Resolved
  • % Done changed from 0 to 100

Applied in changeset r64846.

Updated by Christoph Wagner 10 months ago

Please negate the empty logic as Simon suggested.
I added a patch to do that.

Also available in: Atom PDF