0
votes

in one project I am using the TYPO3 Extension DCE (Dynamic Content Elements). With DCE you are able to create own dynamic content elements without writing an extension.

After creating a content object you can access the created content element with FLUID.

So far so good. Everything works perfect.

Now my problem:

I need to access a variable in a DCE - Element with Typoscript like this:

10 = TEXT
10 {
    field = referenceCustomer
    wrap = <span class="referenceCustomer">|</span>
}

The field referenceCustomer was created by DCE before. With FLUID I can access the field with

{field.referenceCustomer}

I really don't know how to access the generated field..

But whats really confusig, that I am able to access the FAL Image field I've created with DCE in Typoscript..

This code works:

10 = FILES
10 {

    references {
        table = tt_content
        uid.field = uid
        fieldName = referenceImages
    }

    begin = 0
    maxItems = 1

    renderObj = IMAGE
    renderObj {

        file {
            import.data = file:current:uid
            treatIdAsReference = 1
            width = 365c
            height = 125c
        }                                    

        altText.data = file:current:title
        titleText.data = file:current:title
    }

}

Maybe you can help me.. I can't see the wood for the trees..

1

1 Answers

0
votes

To mark this question as solved, I will post the answer by myself.

I made a PHP Userfunc. The UserFunc is able to read the FlexForm Value.

Here is my solution:

The Typoscript object:

includeLibs.FlexformValue =  fileadmin/templates/Utility/UserFunc/FlexformValue.php

5 = USER
5 {
    userFunc = FlexformValue->field
    userFunc {

        uid = TEXT
        uid {
            field = uid
        }

        field = referenceCustomer

    }

}

And the needed PHP UserFunc:

<?php
/***************************************************************
 *  This script is part of the Typo3 project. The Typo3 project is
 *  free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  The GNU General Public License can be found at
 *  http://www.gnu.org/copyleft/gpl.html.
 *
 *  This script is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  This copyright notice MUST APPEAR in all copies of the script!
 ***************************************************************/

class FlexformValue {

    function field($content, $conf) {

        $conf = $conf['userFunc.'];

        $uid = $this->cObj->stdWrap($conf['uid'], $conf['uid.']);

        $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('pi_flexform', 'tt_content', 'uid = ' . $uid);
        $flexform = \TYPO3\CMS\Core\Utility\GeneralUtility::xml2array(current($GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)));

        $this->temporaryDceProperties = array();
        if(is_array($flexform)) {
            $this->getVDefValues($flexform, $this);
        }

        return $this->temporaryDceProperties[$conf['field']];


    }



    /**
     * Flatten the given array and extract all vDEF values. Result is stored in $this->dceProperties.
     *
     * @param array $array flexform data array
     * @param Object $caller
     * @param null|string $arrayKey
     * @return void
     */
    public function getVDefValues(array $array, $caller = NULL, $arrayKey = NULL) {
        if ($caller === NULL) {
            $caller = $this;
        }
        foreach($array as $key => $value) {
            if ($key === 'vDEF') {
                $caller->temporaryDceProperties[substr($arrayKey, 9)] = $value;
            }
            elseif (is_array($value) && array_key_exists('el', $value)) {
                $propertyName = substr($key, 9);
                $values = array();
                $i = 1;
                if (is_array(current($value))) {
                    foreach (current($value) as $entry) {
                        if (is_array($entry)) {
                            $entry = $entry['container_' . $propertyName]['el'];
                            if (is_array($entry)) {
                                foreach($entry as $k => $v) {
                                    $entry[$k] = $v['vDEF'];
                                }
                                $values[$i++] = array('container_' . $propertyName => $entry);
                            }
                        }
                    }
                }
                $caller->temporaryDceProperties[$propertyName] = $values;
            } elseif (is_array($value)) {
                $this->getVDefValues($value, $caller, $key);
            }
        }
    }

}

I hope this answer will help someone who has the same problem then me..

Question solved.