protected function buildTcaWhereClause()
    {
        $tcaWhereClause = '';
        $conditions = [];

        if (isset($GLOBALS['TCA'][$this->type]['ctrl']['delete'])) {
            $conditions['delete'] = $GLOBALS['TCA'][$this->type]['ctrl']['delete'] . ' = 0';
        }

        if (isset($GLOBALS['TCA'][$this->type]['ctrl']['enablecolumns']['disabled'])) {
            $conditions['disabled'] = $GLOBALS['TCA'][$this->type]['ctrl']['enablecolumns']['disabled'] . ' = 0';
        }

        if (isset($GLOBALS['TCA'][$this->type]['ctrl']['enablecolumns']['endtime'])) {
            // only include records with a future endtime or default value (0)
            $endTimeFieldName = $GLOBALS['TCA'][$this->type]['ctrl']['enablecolumns']['endtime'];
            $conditions['endtime'] = '(' . $endTimeFieldName . ' > ' . time() . ' OR ' . $endTimeFieldName . ' = 0)';
        }

        if (BackendUtility::isTableLocalizable($this->type)) {
            $conditions['languageField'] = [
                $GLOBALS['TCA'][$this->type]['ctrl']['languageField'] . ' = 0',
                // default language
                $GLOBALS['TCA'][$this->type]['ctrl']['languageField'] . ' = -1'
                // all languages
            ];
            if (isset($GLOBALS['TCA'][$this->type]['ctrl']['transOrigPointerField'])) {
                $conditions['languageField'][] = $GLOBALS['TCA'][$this->type]['ctrl']['transOrigPointerField'] . ' = 0'; // translations without original language source
            }
            $conditions['languageField'] = '(' . implode(' OR ',
                    $conditions['languageField']) . ')';
        }

        if (!empty($GLOBALS['TCA'][$this->type]['ctrl']['versioningWS'])) {
            // versioning is enabled for this table: exclude draft workspace records
            $conditions['versioningWS'] = 'pid != -1';
        }

        if (count($conditions)) {
            $tcaWhereClause = ' AND ' . implode(' AND ', $conditions);
        }

        return $tcaWhereClause;
    }