Classes/Hook/TCA/RobotsTxtDefault.php
public function main(array $data)
    {
        // ############################
        // Init
        // ############################

        /** @var \TYPO3\CMS\Extbase\Object\ObjectManager objectManager */
        $this->objectManager = GeneralUtility::makeInstance(
            'TYPO3\\CMS\\Extbase\\Object\\ObjectManager'
        );

        /** @var ConfigurationManager configurationManager */
        $this->configurationManager = $this->objectManager->get(
            'TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManager'
        );

        /** @var \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer cObj */
        $this->cObj = $this->objectManager->get('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer');

        // ############################
        // Init TSFE
        // ############################
        $rootPageId = $data['row']['pid'];

        // Disables the time tracker to speed up TypoScript execution
        /** @var \TYPO3\CMS\Core\TimeTracker\TimeTracker $timeTracker */
        $timeTracker = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\TimeTracker\\TimeTracker', false);

        $GLOBALS['TT'] = $timeTracker;
        $GLOBALS['TT']->start();

        /** @var \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController $tsfeController */
        $tsfeController = $this->objectManager->get(
            'TYPO3\\CMS\\Frontend\\Controller\\TypoScriptFrontendController',
            $GLOBALS['TYPO3_CONF_VARS'],
            $rootPageId,
            0
        );

        $GLOBALS['TSFE'] = $tsfeController;

        //allow dynamically robots.txt to be dynamically scripted via TS
        if (empty($GLOBALS['TSFE']->sys_page)) {
            $GLOBALS['TSFE']->sys_page = GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Page\\PageRepository');
            $GLOBALS['TSFE']->initTemplate();
        }

        // ############################
        // Render default robots.txt content
        // ############################

        // Fetch TypoScript setup
        $tsSetup = $this->configurationManager->getConfiguration(
            ConfigurationManager::CONFIGURATION_TYPE_FULL_TYPOSCRIPT,
            'metaseo',
            'plugin'
        );

        $content = '';
        if (!empty($tsSetup['plugin.']['metaseo.']['robotsTxt.'])) {
            $content = $this->cObj->cObjGetSingle(
                $tsSetup['plugin.']['metaseo.']['robotsTxt.']['default'],
                $tsSetup['plugin.']['metaseo.']['robotsTxt.']['default.']
            );
        }

        $content = htmlspecialchars($content);
        $content = nl2br($content);

        return $content;
    }
public function main(array $data)
    {
        // ############################
        // Init
        // ############################

        /** @var \TYPO3\CMS\Extbase\Object\ObjectManager objectManager */
        $this->objectManager = GeneralUtility::makeInstance(
            'TYPO3\\CMS\\Extbase\\Object\\ObjectManager'
        );

        /** @var ConfigurationManager configurationManager */
        $this->configurationManager = $this->objectManager->get(
            'TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManager'
        );

        /** @var \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer cObj */
        $this->cObj = $this->objectManager->get('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer');

        // ############################
        // Init TSFE
        // ############################
        $rootPageId = $data['row']['pid'];

        // Disables the time tracker to speed up TypoScript execution
        /** @var \TYPO3\CMS\Core\TimeTracker\TimeTracker $timeTracker */
        $timeTracker = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\TimeTracker\\TimeTracker', false);

        $GLOBALS['TT'] = $timeTracker;
        $GLOBALS['TT']->start();

        /** @var \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController $tsfeController */
        $tsfeController = $this->objectManager->get(
            'TYPO3\\CMS\\Frontend\\Controller\\TypoScriptFrontendController',
            $GLOBALS['TYPO3_CONF_VARS'],
            $rootPageId,
            0
        );

        $GLOBALS['TSFE'] = $tsfeController;

        //allow dynamically robots.txt to be dynamically scripted via TS
        if (empty($GLOBALS['TSFE']->sys_page)) {
            $GLOBALS['TSFE']->sys_page = GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Page\\PageRepository');
            $GLOBALS['TSFE']->initTemplate();
        }

        // ############################
        // Render default robots.txt content
        // ############################

        // Fetch TypoScript setup
        $tsSetup = $this->configurationManager->getConfiguration(
            ConfigurationManager::CONFIGURATION_TYPE_FULL_TYPOSCRIPT,
            'metaseo',
            'plugin'
        );

        $content = '';
        if (!empty($tsSetup['plugin.']['metaseo.']['robotsTxt.'])) {
            $content = $this->cObj->cObjGetSingle(
                $tsSetup['plugin.']['metaseo.']['robotsTxt.']['default'],
                $tsSetup['plugin.']['metaseo.']['robotsTxt.']['default.']
            );
        }

        $content = htmlspecialchars($content);
        $content = nl2br($content);

        return $content;
    }
public function main ( array $ data ) { // ############################ // Init // ############################ /** @var \TYPO3\CMS\Extbase\Object\ObjectManager objectManager */ $ this -> objectManager = GeneralUtility :: makeInstance ( 'TYPO3\\CMS\\Extbase\\Object\\ObjectManager' ) ; /** @var ConfigurationManager configurationManager */ $ this -> configurationManager = $ this -> objectManager -> get ( 'TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManager' ) ; /** @var \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer cObj */ $ this -> cObj = $ this -> objectManager -> get ( 'TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer' ) ; // ############################ // Init TSFE // ############################ $ rootPageId = $ data [ 'row' ] [ 'pid' ] ; // Disables the time tracker to speed up TypoScript execution /** @var \TYPO3\CMS\Core\TimeTracker\TimeTracker $timeTracker */ $ timeTracker = GeneralUtility :: makeInstance ( 'TYPO3\\CMS\\Core\\TimeTracker\\TimeTracker' , false ) ; $ GLOBALS [ 'TT' ] = $ timeTracker ; $ GLOBALS [ 'TT' ] -> start ( ) ; /** @var \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController $tsfeController */ $ tsfeController = $ this -> objectManager -> get ( 'TYPO3\\CMS\\Frontend\\Controller\\TypoScriptFrontendController' , $ GLOBALS [ 'TYPO3_CONF_VARS' ] , $ rootPageId , 0 ) ; $ GLOBALS [ 'TSFE' ] = $ tsfeController ; //allow dynamically robots.txt to be dynamically scripted via TS if ( empty ( $ GLOBALS [ 'TSFE' ] -> sys_page ) ) { $ GLOBALS [ 'TSFE' ] -> sys_page = GeneralUtility :: makeInstance ( 'TYPO3\\CMS\\Frontend\\Page\\PageRepository' ) ; $ GLOBALS [ 'TSFE' ] -> initTemplate ( ) ; } // ############################ // Render default robots.txt content // ############################ // Fetch TypoScript setup $ tsSetup = $ this -> configurationManager -> getConfiguration ( ConfigurationManager :: CONFIGURATION_TYPE_FULL_TYPOSCRIPT , 'metaseo' , 'plugin' ) ; $ content = '' ; if ( ! empty ( $ tsSetup [ 'plugin.' ] [ 'metaseo.' ] [ 'robotsTxt.' ] ) ) { $ content = $ this -> cObj -> cObjGetSingle ( $ tsSetup [ 'plugin.' ] [ 'metaseo.' ] [ 'robotsTxt.' ] [ 'default' ] , $ tsSetup [ 'plugin.' ] [ 'metaseo.' ] [ 'robotsTxt.' ] [ 'default.' ] ) ; } $ content = htmlspecialchars ( $ content ) ; $ content = nl2br ( $ content ) ; return $ content ; }
Render default Robots.txt from TypoScript Setup

@param  array $data TCE Information array

@return string
Render default Robots . txt from TypoScript Setup