Context

rsyslayout_bootstrap: Context

Auch das ist von der Extension specialty übernommen: setzen eines Contexts, analog zu FLOW3. Siehe dazu die Doku unter github.com/Ecodev/bootstrap_package

Auswahl

Zum Auswählen kann der Kontext in der Extension Konfiguration gesetzt werden. Dazu die Datei ext_conf_template.txt anlegen mit folgendem Inhalt:

# cat=basic//3; type=options[Development,Production,Testing]; label= Context name: Select a context name in which the application will run. @todo move this feature at the Core level somehow. @see forge.typo3.org/issues/39441
context = Development

Dann kann im Extension Manager ausgewählt werden:

 

Vorrang hat das setzen via Apache Konfiguration: .htaccess:

SetEnv TYPO3_CONTEXT Production

Logik

Der Context ist als Klasse realisiert. Dazu die Klassen von specialty kopieren: Classes/Utility/Configuration.php und Classes/Utility/Context.php

Laden

Abhängig vom Kontext werden Typoscript Files mit dem Namen DefaultConfiguration.php geladen aus dem Verzeichnis Configuration/Context/<Context>. Dazu in die ext_localconf.php:

# Development configuration (override default configuration) - set in Extension Manager
$developmentConfigurationFile = sprintf('%s/Configuration/Context/%s/DefaultConfiguration.php',
    \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath($_EXTKEY),
    \TYPO3\CMS\RsyslayoutBootstrap\Utility\Context::getInstance()->getName()
);

if (file_exists($developmentConfigurationFile)) {
    include_once($developmentConfigurationFile);
}

Beispiel:

Configuration/Context/Development/DefaultConfiguration.php

<?php
// Sitename
$TYPO3_CONF_VARS['SYS']['sitename'] = 'Defaultsite Fluid - DEV';
?>

Abfragen in Extension

# condition upon context
if (\TYPO3\CMS\RsyslayoutBootstrap\Utility\Context::getInstance()->isProduction()) {
        // do something
}

# Display the context name
var_dump(\TYPO3\CMS\RsyslayoutBootstrap\Utility\Context::getInstance()->getName());

Erstellt: 06/2013| Geändert: 10/2015

Context ViewHelper

Um den Context auch in Fluid Templates abfragen zu können habe ich einen ViewHelper ContextViewHelper.php geschrieben:

<?php
namespace RSYS\RsyslayoutBootstrap\ViewHelpers;

/*                                                                        *
 * This script is part of the TYPO3 project - inspiring people to share!  *
 *                                                                        *
 * TYPO3 is free software; you can redistribute it and/or modify it under *
 * the terms of the GNU General Public License version 2 as published by  *
 * the Free Software Foundation.                                          *
 *                                                                        *
 * This script is distributed in the hope that it will be useful, but     *
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN-    *
 * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General      *
 * Public License for more details.                                       *
 *                                                                        */

/**
 * shows context
 *
 */
class ContextViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper {

    /**
     * Initialize arguments.
     *
     * @return void
     */
    public function initializeArguments() {
        parent::initializeArguments();
    }

    /**
     * Get context
     *
     * @return string context
     */
    public function render() {
        $context = \TYPO3\CMS\RsyslayoutBootstrap\Utility\Context::getInstance()->getName();
        return $context;
    }
}
?>

Im Template kann man dann den Context ausgeben:

{namespace rsys=RSYS\RsyslayoutBootstrap\ViewHelpers}
{rsys:context()}

Oder eine Condition damit machen:

<f:if condition="{0: '{rsys:context()}'} == {0: 'Development'}">   
    <p class="info well"></p>
</f:if>

Sehr nützliche Sache zum Debuggen etc, ohne in der Produktiv Umgebung dann die Meldungen zu haben, aber man kann kurz den Context umschalten um auch in der Produktivumgebung zu debuggen. Cool!

Erstellt: 08/2013| Geändert: 10/2015