Project

General

Profile

Actions

Bug #77615

closed

Story #69617: FormEngine bugs

_STORAGE_PID not replaced in Flexform

Added by Tizian Schmidlin over 8 years ago. Updated over 4 years ago.

Status:
Rejected
Priority:
Should have
Assignee:
-
Category:
-
Target version:
-
Start date:
2016-08-24
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
7
PHP Version:
Tags:
Complexity:
Is Regression:
No
Sprint Focus:

Description

Hello there,

it seems that with TYPO3 7.6 _STORAGE_PID, aka ###STORAGE_PID### isn't replaced anymore if it is used in flexform conditions.

I figured that \TYPO3\CMS\Backend\Form\FormDataProvider\AbstractItemProvider::buildForeignTableQuery isn't replacing any of it's argument's markers and gives back the data as is.

I added the following to the code and everything seems to work fine again. Although I'm not sure if this is the right place to fix this, I think this issue should be tackled in some manner, or at least that there should be a migration path in order to refrain using ###STORAGE_PID### in flexforms.

/**
     * Build query to fetch foreign records. Helper method of
     * addItemsFromForeignTable(), do not call otherwise.
     *
     * @param array $result Result array
     * @param string $localFieldName Current handle field name
     * @return array Query array ready to be executed via Database->exec_SELECT_queryArray()
     */
    protected function buildForeignTableQuery(array $result, $localFieldName)
    {
        $backendUser = $this->getBackendUser();
        $foreignTableName = $result['processedTca']['columns'][$localFieldName]['config']['foreign_table'];
        $foreignTableClauseArray = $this->processForeignTableClause($result, $foreignTableName, $localFieldName);

        $queryArray = [];
        $queryArray['SELECT'] = BackendUtility::getCommonSelectFields($foreignTableName, $foreignTableName . '.');

        // rootLevel = -1 means that elements can be on the rootlevel OR on any page (pid!=-1)
        // rootLevel = 0 means that elements are not allowed on root level
        // rootLevel = 1 means that elements are only on the root level (pid=0)
        $rootLevel = 0;
        if (isset($GLOBALS['TCA'][$foreignTableName]['ctrl']['rootLevel'])) {
            $rootLevel = $GLOBALS['TCA'][$foreignTableName]['ctrl']['rootLevel'];
        }
        $deleteClause = BackendUtility::deleteClause($foreignTableName);
        if ($rootLevel == 1 || $rootLevel == -1) {
            $pidWhere = $foreignTableName . '.pid' . (($rootLevel == -1) ? '<>-1' : '=0');
            $queryArray['FROM'] = $foreignTableName;
            $queryArray['WHERE'] = $pidWhere . $deleteClause . $foreignTableClauseArray['WHERE'];
        } else {
            $pageClause = $backendUser->getPagePermsClause(1);
            if ($foreignTableName === 'pages') {
                $queryArray['FROM'] = 'pages';
                $queryArray['WHERE'] = '1=1' . $deleteClause . ' AND' . $pageClause . $foreignTableClauseArray['WHERE'];
            } else {
                $queryArray['FROM'] = $foreignTableName . ', pages';
                $queryArray['WHERE'] = 'pages.uid=' . $foreignTableName . '.pid AND pages.deleted=0'
                    . $deleteClause . ' AND' . $pageClause . $foreignTableClauseArray['WHERE'];
            }
        }

        $queryArray['WHERE'] = BackendUtility::replaceMarkersInWhereClause($queryArray['WHERE'], $foreignTableName, $localFieldName, $result['pageTsConfig']['TCEFORM'][$foreignTableName.'.']);

        $queryArray['GROUPBY'] = $foreignTableClauseArray['GROUPBY'];
        $queryArray['ORDERBY'] = $foreignTableClauseArray['ORDERBY'];
        $queryArray['LIMIT'] = $foreignTableClauseArray['LIMIT'];

        return $queryArray;
    }

Regards
Tizian


Related issues 1 (0 open1 closed)

Related to TYPO3 Core - Task #72399: Remove deprecated code from BackendUtility ClosedWouter Wolters2015-12-22

Actions
Actions

Also available in: Atom PDF